I am evaluating Unity3D, having an issue with Quaternion.LookRotation(). Quick background: on the community site there’s a 2D Shooter project that is very enlightening in a number of ways. Our project is also 2D, though it has a “side view” (ie, looking along Z) rather than top down like the 2D shooter.
I’ve switched things around so that the camera can look along Z, but this is where the LookRotation() issue comes in. Basically, I can only get the expected results from LookRotation() when the “upwards” vector is passed as Vector3.up, can’t seem to make this work by passing Vector3.forward to make the up vector be along the Z. What does work is if I transpose the y and z components of the transform positions, do the LookRotation() around Vector3.up, then transpose the resulting Y rotation back around the original Z axis.
Quite prepared to believe I am doing something wrong.
Code:
var newRotation = Quaternion.LookRotation(other.transform.position - me.position, Vector3.forward);
A possible wrinkle is that I am using Blender meshes, which have a 270 degree rotation around X cooked into them (according to the inspector).
If anyone can spot my obvious error, or if this jangles any chords with anyone, I’d be very pleased for the input.
Steve