0

I recently posted a problem with a jittering Camera Follow in my 2D Game made in Unity, which was solved here.

However after some time I noticed, that I am still getting jumps. I now know, that the problem lies in the lerp method of my camera follow. Time.deltaTime varies as described in my prior question and thus makes the player move different distances each frame. But because the camera reacts with a delay, you can see the jump on screen (on device even more than in Unity Editor).

A solution would be to detect those Time.DeltaTime jumps and in these cases make the camera imitate that jump somehow, am I correct? What would be a Workaround here?

These are my scripts:

public class Player: MonoBehaviour 
{ 
    float speed = 5f; 
    void Update() 
    { 
        transform.Translate(0,speed*Time.deltaTime,0); 
    } 
} 

public class CamFollow : MonoBehaviour 
{ 
    public Transform Player; 
    private Vector3 FollowVector; 
    float transition = 0.05f;
    void LateUpdate() 
    { 
        FollowVector = Player.position - new Vector3(0, -4.0f, 10); 
        transform.position = Vector3.Lerp(transform.position, FollowVector, transition); 
    } 
} 
jackjoe85
  • 1
  • 1
  • 2
  • My first instinct would be to try to move your Camera in FixedUpdate instead of Update. The following video might help you to get a better understanding for the differences: https://www.youtube.com/watch?v=MfIsp28TYAQ – Vivien Lynn Jan 16 '21 at 19:31
  • What if you also use `Time.deltaTime` for the interpolation factor? Currently you move a fix `5%` of the distance between current and target position each frame ...maybe rather use e.g. `0.5f * Time.deltaTime` ? – derHugo Jan 16 '21 at 20:02

1 Answers1

0

Try using Time.fixedDeltaTime. This is like deltatime but it's fixed and so it doesn't very as you said. It does reduce the jittering, but I would recommend using Cinemachine, as it's very performant and you would have a lot of control over it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bola Gadalla
  • 370
  • 3
  • 14