So, the repeated mantra is that order matters when it comes to rotation. Rotating the ship locally using the transform did indicate this.
But entering a single line of code using the Quaternion.Euler seems to order Unity to do what we want without any odd implications. To the mathematical ignoramus (i.e. me!) - all this says to me is that this is a fairly typical way to handle rotation without unexpected consequences - but having read (or tried to read) the wiki article on Quaternions - I’m none the wiser as to why simply sticking a new vector 3 in there isn’t the way to do it. Well, I know it isn’t the way to do it because I thought I’d try it, and got an error!
I swapped;
transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
to
transform.localRotation = new Vector3(0f, 90f, 0f);
and Unity spat this at me;
error CS0029: Cannot implicitly convert type ‘UnityEngine.Vector3’ to ‘UnityEngine.Quaternion’
Or in other words, ‘Unity says no!’
Being that I’m almost certain that I’ll never truly understand a fraction of the deeper maths theory behind this, should I just accept it and move on? I’m wondering if that’s what most hobbyist developers do?
I first came across the mysterious Quaternion in a Youtube tutorial a few weeks back. It was aimed at beginners, but this stood out as it was the one thing that the trainer didn’t even attempt to explain, he just said and here is how to set the rotation, you need to use a Quarternion.Euler, as if that should be obvious. My reaction was - what the hell is that??? How is this different to just using a Vector3?
The Unity manual example didn’t exactly shine much light on it either. It actually gives an example of creating a new Vector3 with the floats that represent x,y and z axis, then implanting that into a Quaternion.
So, the transform.localRotation can’t be directly set with a vector3, but it can be set to a Quaternion.Euler, which in turn can be populated using a Vector3?
Man, all I want to do is rotate a 3d model 90 degrees on one of it’s axis then celebrate with a cup of tea! Instead, it’s 3am and I’ve got a headache from trying to understand what this is all about!
But briefly, back to ‘Order Matters…’ From my point of view, does it? I’ve set it and it worked. I use the magical Quaternion that I truly don’t understand and my spaceship is rotated however I want it to. Unless you’re doing something truly complicated in Unity, do you ever need to know any more than that?