I’ve run into a bummer (I’m probably not understanding something here). Basically, I’m making a simply AI script, and I’m adding an offset to a target rotation like this:
However, if I haven’t set AvoidanceOffset to anything, Quaternion.LookRotation seems to have no effect and the object doesn’t rotate. So I decided to do this:
Talking to OP.
(I’m operating under the idea that AvoidanceOffset is a serialized field, which would mean ‘not-set’ would make it the identify quaternion from the get go, since that’s the default quat value when unity deserializes… but yes, if it’s not serialized, then they should be setting it to identity from the get go)
Yep, honestly I didn’t really know the answer and thought as much as you. I didn’t even know identity meant 0,0,0,1 until I looked it up - but posted because he said to compare to 0,0,0,0
Multiplying by the identity quaternion is like multiplying 5 by 1… you still get 5. It’s why it’s called the ‘identity’ vector.
You should be able to just get away with:
TargetRotation *= AvoidanceOffset
And why is your inspector showing the quat as its imaginary parts… why is it not showing as euler? Do you expect people to set the actual quaternion values? I’m good with quats, and I don’t even want to have to sit down and do the maths to calculate the appropriate values for x,y,z,w.
You’re completely right. Because I set AvoidanceOffset to 0,0,0,0, it wasn’t rotating. So I thought that 0,0,0,0 was Quaternion.Identity and that somehow was causing it to not rotate. As soon as I set AvoidanceOffset, the 4th number becomes non-zero and it would rotate properly.
Therefore, I didn’t even need this if I had simply set it correctly the first time. I took out the if statement and it behaves the same.
Can I make the Inspector show Euler angles? I’d love that; it always shows me non-Euler angles for Quaternions.
Thank you for pointing that out, I learned something new today!
Whenever I’ve needed to know the angles of something I just spam the Console. Awful but simple.
Some things just baffle me with Unity. They show Euler angles in the Transform component, but they can’t show them in your scripts? That’s either extreme laziness or bad coding.
I’ll definitely check out the Spacepuppy framework since Quaternion Euler angles in the Inspector would be a great feature to have. Maybe Unity will buy it like they did with TextMeshPro
Oh, don’t take this entire framework just to get euler angles in the editor, like I said, there’s simpler ones out there which I linked.
I actually have to do some pruning to this framework… over the years it has gained some things that turned out we NEVER use. Just haven’t had the time to do the refactoring since we’re in the midst of developing.