I have created a simple smooth follow type script for an orthographic 2d platformer.
At the beginning of each level I use the below code to snap the camera to the players transform.position and then follow him around using lerp. The problem is that the camera snaps to his position on the x and then slowly lerps to his position on the y as I stand still. I can’t for the life of me figure out why it doesn’t properly snap to his x,y
Vector3 pos;
float lerpPosition = 0.0F;
float lerpTime = 300.0F;
// Use this for initialization
void Start () {
pos = GameObject.Find("Astronaut").transform.position;
transform.position = pos;
}
// Update is called once per frame
void Update () {
pos = GameObject.Find("Astronaut").transform.position;
pos = new Vector3(pos.x, pos.y, -10);
lerpPosition += Time.deltaTime/lerpTime;
transform.position = Vector3.Lerp(transform.position,pos,lerpPosition);
}