- Home /
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!
Answer by efge · Mar 31, 2011 at 07:51 PM
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.
I don't have a target rotation (angle in degrees), because the first person controller's camera could be looking up or down or whatever when the Slerp is triggered. The target will be stationary, but the first person will be moving into position (towards its own target position) as well.
Your answer
Follow this Question
Related Questions
Getting angle offset from up vector in quaternion 1 Answer
Convert String to Vector or Rotation via Typecasting? 0 Answers
Python Code for Converting Quaternion to Euler Angles 1 Answer
Quaternion to Matrix Conversion Error - Camera Script 0 Answers
I have global rotations for an object, how do I convert to local rotations? 1 Answer