Ok Quaternions confuse the heck out of me, and if i’m honest I don’t have a great grasp of most 3d math to begin with.
Thing is I have some code that I thought was fine but is now failing in certain conditions and I’m not sure why.
If I raycast an object down to an irregular surface, i then rotate the object to align to the surface normal of where the raycast hit. I do this as follows:
myTransform.rotation *= Quaternion.FomToRotation(myTransform.up, hitNormal);
This works if I spawn an object and drop it down. However if I spawn an object, rotate it randomly along its Up vector(which in this case is the same as world, Vector3.Up) ad THEN drop it down, the rotation I get is often wrong.
I added some debug code to show what my object’s up vector is after the rotation to align to the normal and I noticed something weird. Often the X and Z components of the final up vector are transposed in relation to he surface normal vector.
In other words if the raycast hit.normal is (-0.1, 0.9, 0.5) after using Quaternion.FromToRotation, my object’s Up vector is (0.5, 0.9, -0.1).
Like I said this is an area I am woefully inept at so it figured this is where the bug would be. Can anyone give me some guidance on what I may be missing o where I might be looking to figure out what is going on?