I’m making a 2d racing game, and I want to have the main camera with a top-down view follow the player around. The player is constantly rotating so I cannot simply attach it as a child object… can I lerp it and how would I go about doing it? I could only get the lerp to work with 3 vectors, and I need it to work with just the x and y axis.
don’t parent the camera!!!
add this to the player and this will keep the camera moving towards the difference to where the player started.
public class cameralerp : MonoBehaviour {
public Vector3 diff;
Vector2 v;
public float speed = .1f ;
void Start () {
diff = transform.position-Camera.main.transform.position;
}
void Update () {
v= Vector3.Lerp(Camera.main.transform.position,transform.position+ diff,speed);
Camera.main.transform.position = new Vector3 (v.x, v.y, Camera.main.transform.position.z);
}
}