Rotation Problem

Hey everyone,

Im running once again into a problem with rotating objects through code. Here is my case:

I have a script that helps me make GFXs. Often times, I have an object, like a “disc”, that I want to spin around itself. I know the starting euler angles (from inspector), I know the final euler angles (from inspector as well), and I know how long the interpolation should be. However, as you might guess, interpolating euler angles to rotate doesnt work as planned and the object will make strange angles along the way.

Problem is, the same happens using an Animation Clip. And if I use quaternions, it does work without strange angles, but not as expected, because the Quaternion.Lerp will use the SHORTER way to rotate towards the target rotation… which is a big problem, for example, when making a “slash” that rotates 200 degrees, slashing in the front of the character, the object rotates 160 through the back…

So… what is the best way to rotate something, either through code or Unity’s animation system, in a way that I can rotate it as much as I want, in whatever angles I want, and making it possible to make it rotate 360 degrees, or who knows, even more?

Thanks!

Can’t see why it wouldn’t work with euler angles… Can you post the code you used?

Sure, its not a direct “lerping” but here it is:

First, in editor time, I set the target euler angles (there is a baking process because this same script is responsible for a lot of stuff like lerping positions, material colors, etc etc). I triple checked and this part works correctly.

Then, on runtime, I have the following:

                        if (CurveList[i].X)
                            _currentTargetEulerAngles.x = Mathf.Lerp(_originalLocalEulerAngles.x, _targetEulerAngles.x, curveValue);
                        if (CurveList[i].Y)
                            _currentTargetEulerAngles.y = Mathf.Lerp(_originalLocalEulerAngles.y, _targetEulerAngles.y, curveValue);
                        if (CurveList[i].Z)
                            _currentTargetEulerAngles.z = Mathf.Lerp(_originalLocalEulerAngles.z, _targetEulerAngles.z, curveValue);

Initially I set “_currentTargetEulerAngles” to be = _targetEulerAngles, so by checking if the rotation curve should apply X, Y or Z, I only change that value, that is why Im lerping each axis in a different line. The reason for this mess is that I use animation curves so if I want to make something that rotates a lot on the beginning and slows down… or rotates all the way and then rotates back… I can control these kind of behaviors freely in the curves.

Then, with the “_currentTargetEulerAngles” (which I did triple check as well), I do the following:

                _transform.localRotation = Quaternion.Euler(_currentTargetEulerAngles);

which is just directly applying, as the actual “Lerping” happens above.

The whole system works, and by DebugLogging the value of _currentTargetEulerAngles I know it is lerping correctly, however when this value is applyed to the rotation, the object rotates… strangely, much similar to the effect described in this image: