Some objects working fine at 50 fps, while other objects lagging?

My scene consists of a sphere (that is controlled by the player via touch input) and a bunch of platforms continuously moving upwards (the platforms are continuously spawned via object pooling).

At 60 fps, the movement of all the game objects is smooth. However, at 50 fps only the sphere moves smoothly, whereas the platforms have a very jerky movement.

Here’s the code I’m using to control the sphere’s movement:

Vector3 movement = new Vector3 (horizontal, 0.0f, 0.0f);
rb.AddForce(movement * speed * Time.deltaTime); //rb is the sphere's Rigidbody

And here’s the code I’m using to control the platform’s movement:

//rb is platform's Rigidbody
rb.MovePosition(transform.position + transform.up * Time.fixedDeltaTime * speed);

I always assumed that both Time.deltaTime and Time.fixedDeltaTime would make an object’s movement framerate independent. So why is it that the sphere’s movement is so smooth at 50 fps and the platforms’ movement is so jerky? Am I not using the MovePosition function correctly?

I noticed the same effect at 30 fps. Smooth sphere movement but jerky platform movement.

does your platform need a rigidbody ?
let the physics move the ball, that you are applying forces to.
but for the platform, move the Transform.position. not the rb.MovePosition

You should base all physics on Time.fixedDeltaTime, and increase the rate to more than the framerate in Project settings…->Time->Fixed Timestep (set for example 0.01 for 100Hz). The physics calculation will otherwise be slightly different depending on framerate, and you probably don’t want that.

Since you move the sphere each frame it works smoothly at any rate, but with the above problem.
By setting fixedDeltaTime to a rate at 100Hz the error will be less between frames making the jerkiness better.

There is a few things you can try.


Put the code in the Fixed Update. Just good practice to put physics in movement in here.


Lerp the position of the platform

//rb is platform's Rigidbody
var move = transform.up * Time.fixedDeltaTime * speed;
platform.position = Vector3.Lerp(platform.position, platform.position + move, 1f);