# Quaternion.... angles?

This topic is 2815 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.

q.v = nrmAxis * sin(angleRad)

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

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 23
• 38
• 75