Comments and answers for "Calculate Quaternion.LookRotation manually"
http://answers.unity.com/questions/819699/calculate-quaternionlookrotation-manually.html
The latest comments and answers for the question "Calculate Quaternion.LookRotation manually"Comment by mikii123 on mikii123's answer
http://answers.unity.com/comments/1297132/view.html
This is the best solution I have ever found! I'm making my own engine and was trying to replicate the famous LookRotation function. This algorithm works like a charm!
I used [this code][1] for FromToRotation function.
[1]: http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-finalTue, 10 Jan 2017 17:55:56 GMTmikii123Comment by robertbu on robertbu's answer
http://answers.unity.com/comments/820102/view.html
I don't know if this is an exact match to Quaternion.LookRotation(), but in a bit of testing, it behaves in a similar fashion. What this code does is use the 'up' vector as a normal on a plane. The 'dir + up..' part take the direction and projects it on the plane defined by the 'up' vector. The result is that the first FromToRotation() (line 10) uses the 'up' vector as an axis of rotation. After that rotation is done...after the rotation has aligned things as much as it can using 'up' as the axis...it rotates from that direction to the final direction in a second rotation. Note that if 'dir == up' then you cannot use it as an axis.Wed, 29 Oct 2014 15:00:50 GMTrobertbuComment by hsr38 on hsr38's answer
http://answers.unity.com/comments/819977/view.html
If a millionaire read his answers, please! Buy him a Ferrari. Don't forget to give him an up voteWed, 29 Oct 2014 11:33:41 GMThsr38Comment by hsr38
http://answers.unity.com/comments/819964/view.html
I did see this question before and in fact, it was the one which made me believe that a look rotation would be executed from a quaternion calculation. Before that, I did not even know from where to start. Thanks!Wed, 29 Oct 2014 11:08:57 GMThsr38Comment by hsr38 on hsr38's answer
http://answers.unity.com/comments/819963/view.html
$$anonymous$$y goodness I spent so much time trying to find the solution you wrote! I cannot even imagine how you could possibly arrive at this. Anyway thanks alooooot for your answer.
If you have the time, could you explain why you did multiply the dir+up with the negative dot(up,dir) ?Wed, 29 Oct 2014 11:06:51 GMThsr38Answer by robertbu
http://answers.unity.com/answers/819741/view.html
If I had to write Quaternion.LookRotation(), I might do something like this:
function MyLookRotation(dir : Vector3, up : Vector3) : Quaternion {
if (dir == Vector3.zero) {
Debug.Log("Zero direction in MyLookRotation");
return Quaternion.identity;
}
if (up != dir) {
up.Normalize();
var v = dir + up * -Vector3.Dot(up, dir);
var q = Quaternion.FromToRotation(Vector3.forward, v);
return Quaternion.FromToRotation(v, dir) * q;
}
else {
return Quaternion.FromToRotation(Vector3.forward, dir);
}
}
Note this is built on Quaternion.FromToRotation(), which you would then have to unravel if you need everything from scratch.
http://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-anotherWed, 29 Oct 2014 03:49:47 GMTrobertbuComment by robertbu
http://answers.unity.com/comments/819718/view.html
Not an exact duplicate, but there is some source in this answer:
http://answers.unity3d.com/questions/467614/what-is-the-source-code-of-quaternionlookrotation.htmlWed, 29 Oct 2014 03:00:02 GMTrobertbu