Slerp for x rotation only?

I'm trying to rotate the first person controller's camera on its X axis to look up or down to see a specified object. The look needs to happen over a second or 2.

I found this code in the old first person shooter tutorial:

// Rotate towards target    
    var targetPoint = target.position;
    var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);

How can I get just the x axis rotation from the quaternion so I can have a nice smooth transition?

thanks for any help you can provide!

I figured out my issue. The 'Settings->Can Transition To' was set to true which made it transition to itself before the animation finished. All set now

1 Answer

1

You could use Quaternion.Euler to set the rotation around the x axis in degrees.

Here is an example: Smoothly tilts a transform towards a target rotation.