Calculate differential Euler angles from two Transform.Forward/Up/Right?

I have been having a really bad time trying to find a way to torque a rigidbody around to a target rotation based on its current rotation; the Euler angles are flipping randomly because they’re being extracted from a quat.

Anyway, it occurred to me that I may be able to find the difference in rotation between the two objects (the rigidbody and the target bone) using the directional vectors stored in Transform. In my mind this should be theoretically possible.

What I want to do, specifically, is take the Transform.Forward/Up/Right vectors of one object and compare the angles between the points to the Transform.Forward/Up/Right vectors of the other object.

I’m not sure how this would be achieved, but I’m sure it must be possible. I’m no maths guru by any standard, ha, and I’m struggling to visualise how it would work. If it turns out this is not possible for some reason…well, I may just have to cry a little as this may be my last hope for being able to complete my game in Unity… :cry:

Any help would be much appreciated, and if my question is worded badly or missing information, please don’t hesitate to tell me :slight_smile:

One last thing: I can’t use Quaternions during any stage of this process, because if I do, I have no way of getting Euler angles out again without them being mucked up.

ADDITIONAL INFORMATION

Ok, so I’ve worked out how it would work (for all of the following, assume 0,0,0 is the origin of the angles):

  • To calculate the rotation of the X axis, you calculate the angle between either the Y and Z values of T1.Forward or those of T1.Up, and the Y and Z values of T2.Forward or T2.Up.
  • To calculate the rotation of the Y axis, you calculate the angle between either the X and Z values of T1.Forward or those of T1.Right, and the X and Z values of T2.Forward or T2.Right.
  • To calculate the rotation of the Z axis, you calculate the angle between either the X and Y values of T1.Up or those of T1.Right, and the Y and X values of T2.Up or T2.Right.

I THINK those are correct, but I really don’t know, and it just occurred to me that I don’t know what would happen if any of those coordinates ended up 0,0… Now the only thing I need to know (aside from what to do about the coords being 0,0) is how to actually calculate angles between to points with 0,0,0 as the origin.

This might help you. The code is only lightly tested, but for a question about a HUD for play, I wrote some code to get Heading (yaw), pitch, and roll. You might get what you want by calculating these values for both directions and then subtracting them. I don’t have time today to test/work out if these values would work for angularVelocity.

http://answers.unity3d.com/questions/696271/how-create-modern-aircrafts-hud.html

After all this time, some awesome guy from Stack Overflow solved the very base problem for me :smiley: I posted an answer, because he worked it out entirely in the comments: