Smooth camera movement?

I’m making a 2D game for Android with a camera that only moves up on the Y-axis. I’ve tried everything I know to try to move the camera smoothly, but it still looks jittery when it moves. The game runs at a steady 55-60 fps.

Camera should move up only when the user touches the screen. I currently use Vector3.Lerp to move the camera, but it’s still jittery…

Im not 100% sure on this but i think Vector3.Lerp moves an object gradually between points so if the frame rate changes, so might the movement of the camera. you might want to try using Time.deltaTime. that will move the camera X amount per frame instead of at a set rate

I know, I already use Time.deltaTime. That’s why I don’t understand how the camera still doesn’t move smoothly.

post your code?

public float cameraSpeed = 10f;
public Transform camTransform;

void FixedUpdate()
{
    if(Input.touchCount > 0)
    {
        Vector3 camPos = new Vector3(camTransform.position.x, camTransform.position.y + (cameraSpeed * Time.deltaTime), camTransform.position.z);

        camTransform.position = Vector3.Lerp(camTransform.position, camPos, cameraSpeed);
    }
}

Just a simple upwards movement

might want to try

void LateUpdate ()

LateUpdate is called after all Update functions have been called. This is useful to order script execution. For example a follow camera should always be implemented in LateUpdate because it tracks objects that might have moved

Just tested it on my actual Android phone, and it’s very smooth! :slight_smile:

I’ve tried LateUpdate() before. I could have sworn it didn’t work before… Anyway, thanks for the help.

Oh, hold on.

I just did some more testing and now there’s another problem. I have an object that is moved by its Rigidbody in FixedUpdate and the camera moved in LateUpdate. Whenever the object and camera move at the same time, the camera is smooth but the object is noticeably jittery.

This is strange…

Might be something to do with the peculiarities of FixedUpdate, how it synchronizes with Update and LateUpdate, and how you configure it. I’ll just throw in a couple of links here:

And related threads: