Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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.

0
You could continuously in a loop change Camera.Focus Vulkarin 581 — 6y
0
this works, thanks! XXXlawsonXXX 52 — 6y
0
No problem Vulkarin 581 — 6y

3 answers

Log in to vote
0
Answered by
Shadrz 40
6 years ago

So in a LocalScript you can do this.

local Part = game.Workspace.Part -- Change this to the part
game.CurrentCamera.CameraSubject = Part
0
yes, I have already done this (sorry, should have been more specific). I want to lock the camera to rotate with the ship XXXlawsonXXX 52 — 6y
0
I cannot figure that out, camera is not my expertise. Shadrz 40 — 6y
0
understandable XXXlawsonXXX 52 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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
Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
6 years ago
Edited 6 years ago

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

Answer this question