Comments and answers for "How would I interpret angular displacement from target rotation to max out at 180°?"
http://answers.unity.com/questions/1423042/how-would-i-interpret-angular-displacement-from-ta.html
The latest comments and answers for the question "How would I interpret angular displacement from target rotation to max out at 180°?"Comment by wyatts on wyatts's answer
http://answers.unity.com/comments/1423459/view.html
Thanks for this! It could work, but the Quaternion.Angle() approach was a bit more direct. Cheers!Sat, 21 Oct 2017 00:25:14 GMTwyattsAnswer by wyatts
http://answers.unity.com/answers/1423458/view.html
Thanks Harinezumi! Wow I can't believe I overlooked this. Such a simple tool!!! Definitely simplifies my approach, yet it returned the same result (it goes to 360 instead of maxing out at 180). I actually found a nice bit of code that just maths the numbers over 180 back down :)
public Transform target;
public float angleOut;
void Update () {
var displacement = Quaternion.Angle(target.rotation, transform.rotation);
angleOut = ClampAngle(displacement, 0, 180);
Debug.Log(angleOut);
}
float ClampAngle(float angle, float from, float to) {
if(angle >180) angle = 360 - angle;
angle = Mathf.Clamp(angle, from, to);
if(angle <0) angle = 360 + angle;
return angle;
}Sat, 21 Oct 2017 00:19:54 GMTwyattsAnswer by Harinezumi
http://answers.unity.com/answers/1423133/view.html
Hey @wyatts!
I'm not sure this is what you want, but Quaternion.Angle() gives you the angle between 2 rotations, clamped to a value between 0 and 180, so if you divide it by 180 you'll get a float between [0, 1], maxing out at 180.Fri, 20 Oct 2017 07:56:36 GMTHarinezumiAnswer by pako
http://answers.unity.com/answers/1423127/view.html
Maybe you can use the vector dot product to achieve what you want. Vector3.Dot returns a float between 1 and -1 for normalized vectors. -1 meaning they are pointing in opposite directions, i.e 180deg apart:
https://docs.unity3d.com/ScriptReference/Vector3.Dot.htmlFri, 20 Oct 2017 07:27:34 GMTpako