Hi,
I would like to add a rotation to the camera, which already uses a LookAt method. When I add this code to a file :
void Update () {
float newZ = Input.GetAxis("Horizontal") * -1 * 25;
Vector3 rotEnd = new Vector3( 0, 0, newZ );
transform.eulerAngles += rotEnd;
}
the camera does not rotate with the horizontal axis because of the lookAt method in the CarSmoothFollow script. I am trying to add it directly in the lookAt method, but it does not work correctly, it kind of repeats the rotation 100 times per second. Would you know how to do this? Here is the code :
void LateUpdate () {
wantedHeight = target.position.y + height;
currentHeight = transform.position.y;
//HORIZONTAL
float newZ = Input.GetAxis("Horizontal") * -1 * 25;
Vector3 rotEnd = new Vector3( 0, 0, newZ );
//transform.eulerAngles += rotEnd;
wantedRotationAngle = target.eulerAngles.y;
currentRotationAngle = transform.eulerAngles.y;
currentRotationAngle = Mathf.SmoothDampAngle(currentRotationAngle, wantedRotationAngle, ref yVelocity, rotationSnapTime);
currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
wantedPosition = target.position;
wantedPosition.y = currentHeight;
usedDistance = Mathf.SmoothDampAngle(usedDistance, distance + (parentRigidbody.velocity.magnitude * distanceMultiplier), ref zVelocity, distanceSnapTime);
wantedPosition += Quaternion.Euler(0, currentRotationAngle, 0) * new Vector3(0, 0, -usedDistance);
transform.position = wantedPosition;
transform.LookAt(target.position + lookAtVector + rotEnd);//wrong
}
Thanks