Hi guys, I have a simple camera script set to follow target’s (player) position. I want the camera to stay at a more or less fixed distance from the player but at the moment the faster the player is moving the farther the camera is behind the player.
Any advice?
Camera m_MainCamera;
public Transform target;
public float turnSpeed = 4.0f;
public float minCameraDist = 2.0f;
public float interpolation = 10.0f;
bikeControllerv3 player;
void Start() {
m_MainCamera = Camera.main;
m_MainCamera.enabled = true;
player = FindObjectOfType<bikeControllerv3>();
}
void FixedUpdate() {
float dist = Vector3.Distance (transform.position, target.position);
Vector3 position = this.transform.position;
position.y = Mathf.Lerp(this.transform.position.y, target.transform.position.y, interpolation);
position.x = Mathf.Lerp(this.transform.position.x, target.transform.position.x, interpolation);
position.z = Mathf.Lerp(this.transform.position.z, target.transform.position.z, interpolation);
this.transform.position = position;
transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, turnSpeed*Time.deltaTime);
}