So I’m trying to create a game that tracks a moving car, but instead of doing it from the side, I want to track it from the top. To achieve this, I need the camera to lock onto the car from above. However, I’m encountering difficulties in doing so. The specific part I’m referring to is called the “mainpart.” Can anyone assist me with this issue?
this code should set the camera’s cframe to mainpart’s cframe everytime it changes,
local camera = workspace:WaitForChild("CurrentCamera")
local MainPart = -- the path to mainpart
MainPart:GetPropertyChangedSignal("CFrame"):Connect(function()
camera.CFrame = MainPart.CFrame
end)
(dont forget to set camera’s type to scriptable aswell)
try setting the camera subject to the part that you want the camera to be attached to.
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Follow
game.Workspace.CurrentCamera.CFrame = game.Workspace.Mainpart --Main part
game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Mainpart --Main part