Basically, I want to check if the subobject’s X-axis is rotated more than a given number of degrees off the parent’s X-axis (“blue arrow” in Local Space).
I tried many things to this end, and I’m fairly sure one of the functions does what I want (FromToRotation? LookRotation? AngleAxis?), but all give me confusing results, likely due to faulty usage. I’m assuming this is because most of these look for the angle difference on all axis, whereas I am just interested in the “shortest” rotation needed to align the subobject’s local X direction to the parent’s one. Both Y and Z rotation can start and end wherever they want, I don’t care about them.
My current attempt (where the given angle limit is 40°):
Quaternion targetdir= Quaternion.Euler(Vector3.forward);
if (Quaternion.Angle(sub.transform.localRotation, targetdir) > 40)
return false;
else
return true;
I’m really confused by the whole mess I’ve gotten myself into, but I can’t shake the feeling there must be a fairly simple solution to my problem.
Maybe one of you can help?