I’m using Quaternion.Lerp to rotate a joint with a certain angle, but when I use the below code I find the joint rotating very far although I specified it to rotate with only 5. Any thoughts please?
Next time use code tags as it’s easier to read ^-^
First off, if it were me I would use Quaternion.Slerp instead of Lerp. This is because the docs say Lerp looks worse when rotations are far apart. (Probably at the expense of a little performance) Secondly, if you are updating newRot.y for every frame, of course it will go more than 5. Since currentTransform is changing every frame (due to the Lerp) and you are adding to that + 5 every frame, then it will increase beyond just 5. So you should set your newRot only once at the start.
Third, your first parameter of Quatnerion.Lerp should be the initial. But yet you are updating it every frame because you’re setting it to the localRotation. So instead, at the same time you should be setting newRot only once at start, you should set animationRotation only once at start. That way it can move between the two at the correct blendweight instead of setting a new initial rotation every frame. (It still works the other way, but you end up with an exponential blend, which is ugly–it never actually reaches newRotation–and is probably not what you want) Well maybe exponential isn’t ugly considering it’s an animation joint haha but it’s probably bad practice. If you still want exponential might be a better idea to add exponentially to blendweight instead of resetting initial every frame.
“currentTransform.localRotation.y +5f;” isn’t anything that makes any sense. Quaternions are 4D, with each element ranging from -1.0 to 1.0, and the y element isn’t related to the Y axis. Also, to use Lerp correctly, you need to advance the third parameter from 0.0 to 1.0 over time while keeping the first and second parameters the same; your code does something quite different from that. I’d recommend using coroutines instead of Update for Lerp, since they’re easier to start and stop when needed. See here for an example of slerping over time with a coroutine.
but like if I didn’t use the lerp and only used this “currentTransform.Rotate(newRot);” it works as anticipated and the limb’s joint only rotates a little bit, but it kinds of jump directly to the new rotation without smooth transition. So not sure how can I apply this rotation with smooth rotations.