Reply To: Animating local transform?

Slate Forums Support Animating local transform? Reply To: Animating local transform?

#1812
dgoyette
Participant

I played around with this a bit more. The issue is that Lerp just does plain old math, without any concern for the different ways Vector3s can be equivalent. So, (180,0,0) is the same as (-180,0,0), but will produce different lerp results when used as the Start or End of a Lerp.

So, before calling Lerp to determine the rotation, I first need to clean up the target rotation so that none of the component differences (Mathf.Abs(original.x – target.x), for example) exceeds 180. Here’s what I’m doing, which seems to work properly, though I assume there’s a more efficient approach. The following is the OnUpdate method of my LocalRotateTo action clip. Note the use of GetShortestResult to adjust the targetRotation to create an equivalent Vector3 that minimizes the rotation:

So now my LocalRotateTo always takes the shortest rotation instead of doing backflips or pirouettes. 🙂