I’m trying to find the difference in two angles and apply that difference to another angle but Eulers and Quaternions are confusing me and I’m not getting any results that are satisfactory, I have searched so many forums and googled so many variations without success.
My goal is basically to get the difference in angle between Vector3.up and the normal of a platform that is tilted, for example, 45 degrees:
So I start by determining Vector3.up (Red) and raycasting down from my character and finding the normal (Blue) of the surface hit (Black), then I get the direction that my player is facing (Green) and I want the angle (Yellow) that is the same distance away from green, that blue is away from red.
The picture makes it look easy but platforms will vary in angles and it’ll change in real time, so no angles are foreknown.
Out of all the research I’ve done with angles in Unity, quaternions seem like the best idea, but I’m getting inconsistent results using functions like Quaternion.Inverse to get the delta angle of two quaternions (up and normal).
I’ve tried using Euler and got close to what I wanted, however it never yielded the correct angle off-set to my facing direction. It returned the difference in angle between up and normal, but wouldn’t correctly apply the same off-set to any other direction.
I’ve been using Debug.DrawRay to test all these angles, which raised different problems. The command uses a Vector3 as a direction so I need to convert a quaternion direction into a Vector3 for debug purposes, which seems to yield weird results most of the time. So instead I tried putting in an empty object and applying the quaternion rotation to that and then using that object’s transform.forward vector3 as the drawray direction. This worked but the whole process has left me confused as to how exactly to manipulate angles in the way in which I want without having to using a transform as a medium.
Finally, what has also confused me, is that sometimes Vector3 angles are of magnitude 0-360 and sometimes -1 to 1. I don’t really understand why this is so or how to convert between them.
Any help or advice is greatly appreciated.
Dan