Why is an object's movement jerky, when the camera is also moving by following a different rigidbody?

I’ve seen a bunch of similar questions to this, but so far everything suggested hasn’t helped me.

My set-up is as follows;

  1. A capsule, that is moving with constant speed, using:

    void Update()
    {
    transform.position += new Vector3(Time.deltaTime, 0, 0);
    }

  2. A sphere with a rigidbody, that is set to move on player input:

    void FixedUpdate()
    {
    if (Input.GetKey(KeyCode.D))
    {
    GetComponent().AddForce(new Vector3(1, 0, 0));
    }
    }

  3. A camera, set to follow the sphere (with some z offset, to keep everything in view):

    void LateUpdate()
    {
    transform.position = Sphere.GetComponent().position + new Vector3(0, 0, -5);
    }
    With the capsule using Update, the sphere using FixedUpdate and the camera using LateUpdate (as above), the following gfy shows what happens:

As you can see, when the camera is moving, the capsule movement is really jerky.

Alternatively, if I move the capsule code into FixedUpdate, it becomes:

Which is better, but still not perfect. In particular, the capsule movement appears jerky in the beginning, when the camera is stationary. (This isn’t very noticeable in the gfy, but trust me, it’s worse in real time!)

I’ve tried various other combinations of Update types, along with changing the interpolation of the rigidbody, all to no avail.

Is there any way to get the capsule moving smoothly all the time, regardless of camera motion? Or am I going to have to learn to live with it?

With Update(), the problem is framerate, so isn’t moving constantly according to the display perception.

In FixedUpdate(), the capsule is moving constantly, but you’re still perceiving it as moving according to the display.

The problem is actually the camera following the sphere. AddForce doesn’t do the same thing as just constantly updating the position like with the capsule. The movement that you are seeing in the capsule is both the camera and the sphere moving tiny bits because of the engine physics not moving the sphere at an explicitly constant speed, but since the camera is following the sphere, the sphere looks like it’s the one that isn’t moving.

I had similar issue. Turns out that apparently RigidBody updates its position only in FixedUpdate (along with the physics and applied forces). In Inspector I set my rigid body’s Interpolation to interpolate. The jagged movement turned into a pretty smooth one. To be sure there are no rapid changes in the object movement I also smoothed the force applied to the object (but that may not be desired behaviour - it’s case dependant but worked very well for me):

private Vector3 lastAcceleration = Vector3.zero;
private const float damping = 0.7f;
[SerializeField]
private RigidBody2D rb;
private void FixedUpdate()
{
	Vector3 acceleration = Vector3.zero;
	acceleration = /* Calculate Your acceleration here */
	lastAcceleration = Vector3.Lerp( acceleration, lastAcceleration, damping);
	rb.AddForce( lastAcceleration, ForceMode2D.Force );
}

As a general rule: if something needs to “follow” Rigidbody by updating transform.position, such updates should happen in FixedUpdate. Camera is not an exception, so changing LateUpdate to FixedUpdate in camera resolved all the jerkiness issues for me.


(Context: I had the same problem with trying to make camera follow the object with some smooth time via Vector3.SmoothDamp. It appeared well when setting smooth time to 0, but any positive value resulted in player being rendered inconsistently/jerky/jagged.)