Jittering while camera is moving

I have a weird problem that happens only in build and not in editor. In short I took the vehicle example, I removed the part of code that moved camera and wrote my own camera follow script:

public class CameraFollow : Script
{
    public Actor Target;

    public float CameraDistance = 500.0f;

    public override void OnFixedUpdate()
    {
        var transform = Actor.Transform;
   
        var targetPos = Target.Position + Vector3.Up * 100;
        var direction = (targetPos - Actor.Position).Normalized;

        transform.Translation = targetPos - CameraDistance * direction;
        transform.Orientation = Quaternion.Invert(Quaternion.LookAt(transform.Translation, Target.Position));

        Actor.Transform = transform;
    }
}

In editor everything seems absolutely fine but when I build and run my game, car that is followed by camera jitters while moving. Also I don’t think it is a physics problem because when camera is stationary another car moves smoothly same as in editor.
Recorded problem here.

Also sometimes when I build it works fine but that happened like three times and when I build again without changing anything it doesn’t work.

I have no idea why this is happening, help would be appreciated.

A tip is the camera code should not be in fixed update, but rather just update. You can also use the Lerp function for transform to assist in smoothing your camera movement out. I have seen people also have better results when they change their Time settings around the target fps.

1 Like

Lerp seems to fix this. Thank you for your help.