Question by
Daisy-Chain-Games · Dec 02, 2016 at 07:41 PM ·
2d gametime.deltatimecamera follow
Time.deltaTime Stuck Camera
I'm trying to make my camera follow function smooth in my 2D game but by adding Time.deltaTime to my code, it makes it stuck with its X axis rumbling a tiny bit.
Here is my code:
#pragma strict
var target : Transform;
var offCentre = 0;
function Update ()
{
transform.position.x = (target.position.x - offCentre) * Time.deltaTime;
}
Am I doing something wrong or am I forgetting something?
Comment
Answer by hexagonius · Dec 02, 2016 at 10:42 PM
you're setting a definite world space position each frame, but multiplying it with deltaTime changes it slightly every time. the further you're away from the scene center, the bigger the impact. try using this:
transform.position.x = Mathf.MoveTowards(target.position.x - offCentre, Time.deltaTime);