Answers for "Calculating the difference between forward direction and velocity direction to set the body roll of my vehicle."
http://answers.unity.com/questions/1086228/calculating-the-difference-between-forward-directi.html
The latest answers for the question "Calculating the difference between forward direction and velocity direction to set the body roll of my vehicle."Answer by Glurth
http://answers.unity.com/answers/1086270/view.html
Your code looks like its does ALMOST exactly this:
"To to sum up, I'm looking to take the y rotation of my object and subtract the y rotation of its velocity divide the value by two and then use it to add body roll to my object on the z axis. "
With the one exception: you are REPLACING the rotation of the object with this, rather than adding to it.
transform.eulerAngle = new Vector3 (0, 0, rollAngle);
If you wish to rotate the existing orientation, by that angle try something likethis:
transform.rotation = transform.rotation * Quaternion.Euler(0, 0, rollAngle);
(it uses this operator to combine the rotatations: http://docs.unity3d.com/ScriptReference/Quaternion-operator_multiply.html)
Edit: note-the above operator "adds" the second Quaternion to the First. If you wish to reverse the rotation of the second Quaternion to do a "subtraction", use http://docs.unity3d.com/ScriptReference/Quaternion.Inverse.html ,like so:
transform.rotation = transform.rotation * Quaternion.Inverse(Quaternion.Euler(0, 0, rollAngle));
(silly in this case, because you could have just used `rollAngle * -1` to begin with)Thu, 22 Oct 2015 15:46:31 GMTGlurth