Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there any way to "attach" the camera to a moving part?

I have a spaceship that will move towards the mouse position when pressing W. When you control it, you have to constantly readjust the camera to face the direction you would like to go. Is there a way to make the camera act as if it was moving with the ship?

Also it would be good to mention that the ship is controlled in 3rd person.

I have tried to set the CFrame of the camera to be behind the ship but it is very jittery and doesn't rotate.

3 comments

0

You could continuously in a loop change Camera.Focus

0

this works, thanks!

0

No problem

3 answers

So in a LocalScript you can do this.

local Part = game.Workspace.Part -- Change this to the part
game.CurrentCamera.CameraSubject = Part

3 comments

0

yes, I have already done this (sorry, should have been more specific). I want to lock the camera to rotate with the ship

0

I cannot figure that out, camera is not my expertise.

0

understandable

Sounds like you want to change the CameraType of the camera to either Follow or Attach.

workspace.CurrentCamera.CameraType = Enum.CameraType.Follow
-- or
workspace.CurrentCamera.CameraType = Enum.CameraType.Attach

Well, it's simple. You just have to loop around the line of code so it keeps changing. and i do recommend changing the camera's cframe instead of its subject

local camerapart = script.Parent --put the attached part here
local camera = workspace.CurrentCamera

while true do
	wait(0.01) --make this lower if it's not keeping up
	camera.CFrame = camerapart.CFrame
end
	

this script might not work cuz i suck or i might not understanded what you said. and idk if theres another efficent way

This discussion is preserved as it was. New answers, comments, and votes are closed.