Camera rotation using lerp issue

I have code to look between different points and i want a smooth transition so I am trying to use lerp but it still jumps straight to each rotation without any transition. Inside the fps script I have:

  • on switch view button press{
  • lookTarget = transform;
  • lookTarget.LookAt(waypoints [viewWaypoint]);
  • }
  • void RotateView()
  • {
  • transform.rotation =Quaternion.Lerp(transform.rotation, lookTarget.rotation,Time.deltaTime*10);
  • }

Any ideas??

This immediately rotates the transform. lookTarget and transform are one and the same.

I’d recommend using this as your second parameter in the Lerp:

 Quaternion.LookRotation(waypoints[viewWaypoint] - transform.position)

Also, when using Quaternion, you generally get better results with .Slerp instead.

Thanks for reply. Yes it immediately rotates the lookTarget rotation, but shouldn’t this work as I am using Lerp between the actual transform of the camera and the end point (lookTarget) rotation? Just trying to understand why this isn’t working. I’ll check out the.slerp as well. Thanks again.

When you set lookTarget = transform, they are now pointing to the same object. It’s not like setting one integer to another; they don’t merely have the same values. They are literally the same thing, and when you change lookTarget, you are changing transform. Look up the difference between value types (such as int, float, Vector3, Color) and reference types for further reading.