Weird : scrolling smoother in Update that FixedUpate function

Hi guys,

I’m scrolling a GameObject using its transform.position - At first I put the code in the Update function and then thought it was physic related so I moved the code to the FixedUpdate function. When the code was in the Update function the scrolling was very smooth whereas in the FixedUpdate function the scrolling is laggy. I tried to add or remove a rigidbody2D into my GameObject but I didn’t see any differences.

The code :

void Update () {

        Vector3 newPos = new Vector3(gameObject.transform.position.x,gameObject.transform.position.y,0);
        newPos.y -=  Speed * ParallaxFactor * Time.deltaTime;

        gameObject.transform.position = newPos;
    }

Is that normal ? Am I doing the right thing ?

Thank you

If the update function runs every frame and your quality settings aren’t set to sync to the vblank (vertical blank), then the framerate graphically will be very high and things will appear smoother. fixed update is likely defaulting to 50fps or less and so will appear jerkier in comparison. Fixed update can become smooth in various ways … physics interpolation etc.

FixedUpdate should only be used for physics, since it’s synced to the physics timestep. Moving objects manually should always be done every frame; FixedUpdate typically doesn’t run every frame.

–Eric

1 Like

Thank you for your explanations !