Smooth Moving Camera?

Basically, what I’m trying to do is make the character’s camera really smooth, that means when you’ve turned your camera it’s rotating still even if you’ve stopped. Like its not instant, and has momentum? If you know what I mean…

If you could help it would be really appreciated, and I’m thinking if tweening would work. However, I don’t know what to start with.

7 Likes

I think CFrame lerping would be the way to go.

5 Likes

Check out this scripting helpers thread.

1 Like

You should use a for loop for nice movement. I suggest looking it up.

I wouldn’t use a for loop, I would use RunService.RenderStepped or RunService:BindToRenderStep. That way you’re guaranteed to have your code run every time a frame is rendered, making for a much smoother transition.

1 Like

I would use renderstepped and save the mouse delta in a vector and update that by lerping it to the current mouse delta. In this way the cameras movement accelerates and deaccelerates at a different rate than the user moves their mouse, creating that effect of smoothness. Then you could just apply the lerped vector to the camera’s rotation.

Heres a simplified explanation
Instead of

CameraRotation = CameraRotation + MouseMovement

You want something along the lines of

Velocity = Velocity + MouseMovement
Velocity = Velocity * Drag
CameraRotation = CameraRotation + Velocity

This is a (very) simplified way of explaining it, but should give you a basic idea of how to implement it. Using Lerp would get you a smooth effect, however lerp would just ‘slow down’ the camera movement, so it gradually moves from its current rotation to where the mouse tells it to move. A velocity based system would mean the camera moves how it did before, but continues to move after the mouse stops moving.

To start off, try setting CameraType to Scriptable, and try get a script working to read mouse delta X and Y using UserInputService.

Hope this helps :slight_smile:

3 Likes