- Home /
How to get angular difference?
I have a hierarchy (game objects nested) where I need to find the local angle between objects. Think 'shoulder/elbow/wrist' and I need to know the angle on the elbow. But not just the current angle (I know about Eulers), but the difference between the last-frame's angle and this frame's angles. I can save off the rotation values and/or positions from frame to frame, but is there a way to mathematically determine that the angle has, for example, changed by 5 degrees?
Answer by maccabbe · Mar 28, 2015 at 05:02 AM
Save the rotation each frame and use Quaternion.Angle with the old rotation and current rotation as the parameters, i.e.
Quaternion oldRotation;
void Start(){
oldRotation=transform.rotation;
}
void Update(){
Debug.Log(Quaternion.Angle(oldRotation, transform.rotation));
oldRotation=transform.rotation;
}
Answer by hexagonius · Mar 28, 2015 at 02:20 AM
I would say using Vector3.Angle on shoulder to elbow and elbow to wrist would tell you the current one. If you save that every frame it's just a small step to the difference from last to current angle