# Quaternion.... angles?

This topic is 2510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working in Unity and I'm trying to get an enemy to turn a certain way. Doing it with Euler angles is just not working and using quaternions works better, but still isn't quite there. Basically, imagine an enemy standing up straight and rotating him so the top of his head points at a desired position. This is only on 2 axis, so to get the angle I want to rotate I do

 vec = targetPos - position; vec = vec.normalize; dotProd = Vector3.Dot((Vector3.up), vec); angleToTarget = Mathf.Acos(dotProd) * (180/Mathf.PI); 

So now I have the angle I want to rotate. I want to do this rotation about the X axis, since that is the axis that goes into the screen for me. How would I go about modifying the existing quanternion that is being used for rotations (which is just the identity quaternion) so it will rotate the object for the calculated angle about the X axis?

##### Share on other sites
Try a Quaternion from axis angle. You have the angle, you know you want to rotate about the x axis.

then combine this quaternion with the existing one, and use the result.

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013601
×