Hi all,
So I have an interpretation of the SmoothFollow script but written in C#
I have added a Ray to the back of the camera and at the moment the camera will hit the wall and the camera will stop. The car will then reverse untill it hits the wall.
When I drive off, the camera stays where it is because of the Ray
How can I get the camera to carry on following the car when it moves off again?
Thank you
void Update ()
{
float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
if (!target)
return;
Vector3 back = transform.TransformDirection(Vector3.back);
Debug.DrawRay(transform.position, back * 1, Color.green);
if (Physics.Raycast(transform.position, back, 1))
{
Debug.DrawRay(transform.position, back * 1, Color.black);
} else
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
transform.LookAt (target);
}
}
}