Hello I would really like to get the difference between two rotations on a given axis (say, transform.up or .forward).
Basically I just need to work out how far to rotate something, and which direction to rotate it in. Quaternion.Angle() does not help as it doesn’t give me a direction.
Could anyone help? I’m really struggling with this.
2 Answers
2
The true answer is:
Vector3.SignedAngle(target-transform.position, transform.forward, transform.up);
You can use Quaternion.Angle() static function to know angle between quaternions.
float angle = Quaternion.Angle( objA.transform, objB.transform );
Thank you, but how do I know which direction the rotation is in? Just getting the angle isn't very helpful. Is it moving left or right?
– TiggyFairyThe direction depends on whether you pass in a negative or positive value. If you want to go left, you want a negative value, if you want to go right, you want a positive value.
– Waterstudios11The problem is my AI doesn't know if it wants to go left or right, and how many steps. That's what I'm trying to work out here.
– TiggyFairy