So, I was coding some simple direction rotation stuff like this;
rotation.Value = Quaternion.Euler(0, 0, 90);
And that worked, hard 90 degrees corner on my sprite. Somewhere else I had;
rotation.Value = quaternion.Euler(0, 0, 90);
And that didn’t work. Having an actual rotation of about 0.85 on the z instead of the 0.70 or so I’d expect. Now, Quaternion, is from UnityEngine and quaternion is from Unity.Mathematics. Is that intentional, did I stumble upon something strange or don’t I understand quaternions yet again.
Okay, that does solve some part. Thanks. The other question is somewhat related; why is turning towards another object not working;
Here is the thing. I build a simple turn toward script, doing all the work manually. Now, i’d like to simplify this, using code from the Unity example video, this bit;
For test purposes hard coded, I’d expect the object at 0,0,0 to turn 45 degrees towards the target at 10,10,0.
However, no such thing happens. Instead I get rotations on the x and y while I’d expect only on the z.
The first part I can do, the second, what does that mean? The object is a flat sprite, I I rotate by “hand” and convert and set the z that way, it works. But using LookRotationSafe doesn’t change anything. It sill doesn’t rotate like i’d expect.
For LookRotation, it didn’t work because your vector is not normalized. LookRotationSafe will not only normalize your vector but when the result is invalid, it will return an identity value.
IMHO that’s the best part of the math package. You are not wasting operations normalizing a already normalized vector. Or having to convert an value in radians to degrees just to be converted to radians again.
About your result in rotation, they are correct. You are expecting the look using the X as a forward when is Z.
But that doesn’t do anything. As in the rotation value never gets changed. When I log the value, it gets changed, in the debugger it does change. But, in the game window itself, it doesn’t rotate the sprite at all.