I have a problem rotating an object with quaternion, when I rotate the object I use the function slerp to rotate from one rotation to another, but in this process the object loses its local Y axis rotation, so I want to know how could this be avoided, the code that I use:
var orgRot = transform.rotation;
var myForward = Vector3.Cross(transform.right, normal);
var dstRot = Quaternion.LookRotation(myForward, normal);
for (var t: float = 0.0; t < 1.0; ){
t += Time.deltaTime*2;
transform.rotation = Quaternion.Slerp(orgRot, dstRot, t);
yield;
}
There are a number of techniques for solving this kind of problem, but in order to suggest one, I'd need a firm understanding of 1) what rotation you are looking for, and 2) a better idea of how this code is failing you. Images are good. Video can be helpful.
– robertbuAnd finally the character in the new surface, and now the character is looking forward, when actually he should be looking to the left ( which is forward in the third picture) http://answers.unity3d.com/storage/temp/33848-3.png Maybe the explanation is not clear, if it is the case, I will upload a video to youtube
– sr388If I can getting a really clear idea of the rotation needed, I can almost always figure out the code. Here I'm still guessing. Maybe you are looking for this: var dstRot = Quaternion.FromToRotation(transform.up, normal) * transform.rotation;
– robertbuThat is exactly what I needed, now the character rotates from one surface to another correctly, and he makes a more natural movement, it is just I didn't undertand all the quaternion functions , thank you very much for the help robertbu
– sr388