Well, I have been working on a character animation program for tablet devices for a while now called “Touch Animator”. The biggest problem I am having is that when an object animates, the rotations do not happen in a predictable or useful fashion. I have tried Quaternion.Slerp, setting the angles directly, and all sorts of other solutions. Maybe I am just not implementing these correctly. Anyway, i posted a video which clearly lays out the problem andthe script that controls the rotation. After searching the forumsI have found that several other people have similar issues so a solution could benefit us all.
I told you before to use Quaternions and slerp. Did you try this?
I also told you that Euler is pronounced Oi-ler ![]()
here’s an example:
WebPlayer
import System.Collections.Generic;
private var animationFrames : List.<Quaternion>;
private var isAnimationPlaying : boolean = false;
function Start()
{
animationFrames = new List.<Quaternion>();
animationFrames.Add(transform.rotation);
}
function OnGUI()
{
if(GUI.RepeatButton(Rect(0,10,32,32),"-"))
{
transform.eulerAngles.y -= 1;
}
if(GUI.RepeatButton(Rect(50,10,32,32),"+"))
{
transform.eulerAngles.y += 1;
}
if(GUI.Button(Rect(0,50,40,32),"Key"))
{
animationFrames.Add(transform.rotation);
}
if(GUI.Button(Rect(50,50,40,32),"Play"))
{
if(!isAnimationPlaying)
PlayAnimation();
}
}
function PlayAnimation ()
{
var i : int = 0;
isAnimationPlaying = true;
while (i < animationFrames.Count-1)
{
transform.rotation = animationFrames[i];
yield Rotate(animationFrames[i+1],1);
i++;
}
isAnimationPlaying = false;
}
function Rotate (endRotation : Quaternion, time : float) {
var startRotation = transform.rotation;
var rate = 1.0/time;
var t = 0.0;
while (t < 1.0)
{
t += Time.deltaTime * rate;
transform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}
}
644111–23033–$AnimationTest.zip (169 KB)