Hmmm
Implementation wise, this function only stabilizes the basis vectors, so that the rolling rotation is well-defined.
And so it takes your vectors and gets a cross product which is the “arrow of stabilization”.
That said, a cross product of two identical vectors gets you a degenerate case, a vector with a magnitude of 0 (no parallelogram can be made). And this is why it is said it will behave the same as if your vectors were of magnitude of 0.
I think you also got the correct rotation.
I’m guessing it did work only because it was an orthogonal case.
In other words, try with Vector3.one.normalized, see what you’ll get.
I managed to implement something that behaves identical to LookRotation, and from this it is possible to infer that Unity’s implementation does something differently. It seems to be testing for a scenario that is mathematically undefined and corrects it. I think it has to do with singularities (they assume that only singularities aren’t well defined) but without the original source code it’s hard to tell.
In any case, what docs state is true, UNLESS you also introduce a condition for this test, then it simply snaps to one of the two possible cases. You can compare this if you make a test environment.
(Excuse the negative signs, I modified a solution that had the “wrong” hand rule.)
Therefore the result should really be (0.5, 0, 0, -0.5), however it is also invalid (and behaves like a discontinuity), while Unity prevents this but definitely fails to detect that the vectors were collinear to begin with.
The solution (that would marry this code’s results with Unity’s) is to introduce just one check after line 3
if(right.sqrMagnitude == 0f) right = Vector3.right;
I wasn’t able to reproduce any errors or differences between two algorithms (my tests were naive, but thorough, still I wouldn’t call this claim 100% error-proof). It also behaves the same when vectors are (0,0,0). I specifically tried all orthogonal configurations.
Btw the original code is basically the same, the reason why I dismissed it was because I didn’t have the proper environment and it gave a different answer.