What do you want to achieve?
I would like to script smooth camera movement to follow a specific part in my game (it’s labeled as mainBCell or brain cell).
What is the issue?
Currently, I am CFraming the camera constantly using run service. This results in choppy camera movement.
Here is a link to the video: https://gyazo.com/4f4acb9da44b62cbde807167882047f5
Here’s the code too if anyone wants to see it:
--Sets camera to the center cell, enables top-down
camera.CFrame = CFrame.new(0, 20, 0) * mainBCell.CFrame * CFrame.Angles(math.rad(-90),math.rad(-90),math.rad(-90))
--Live update Camera
local function onUpdate()
--Note that it locks the orientation, it is a cylinder that looks more like a circle.
mainBCell.Orientation = Vector3.new(0,0,90)
--Height is a variable so I can change the camera height during the game.
camera.CFrame = CFrame.new(0, height, 0) * mainBCell.CFrame * CFrame.Angles(math.rad(-90),math.rad(-270),math.rad(-90))
end
RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
What solutions have you tried so far?
Currently, the part mainBCell is moved using a remote event and a Legacy BodyVelocity (I know, but it runs much smoother with the fixed orientation). I think tweening might work, but how would I go about doing that?
Another idea of mine is to apply another BodyVelocity (Just go with me here, if you really don’t like my usage, tell me how to use a VectorForce…) However, the server cannot interact with the player’s camera.
Which idea is the best, and how would I go about doing it? Thanks, Someperson576
You could try lerping the camera’s CFrame to the CFrame of the mainBCell. This can make the movement to the mainBCell much smoother. CFrame | Documentation - Roblox Creator Hub (under Functions)
For a test try tweening the camera CFrame to a random part’s CFrame and see if it works and if it does you know its an issue on how your calculating the CFrame.
I tested everything, and camera:Interpolate works! Thank you everyone!
I do have two questions though,
A. What does setting the mainBCell as the camera’s focus do? B. For future reference with interpolating cframes, what exactly is the number alpha (or fraction alpha).