- Home /
Question by
SYRSA · Jul 12, 2013 at 09:58 PM ·
animationangularvelocity
I want to make this script animate depending on angular velocity
Here is a script that animates and adjusting the speed of the animation depending on the velocity of the direction. But it cannot animate depending on the angular motion. How can I make so that It can do that?
This is a line that is supposed to do it, but it's wrong: animation[right].speed = Mathf.Clamp(Mathf.Abs(relative.z) / rightSpinSpeed, 0, maxAnimationSpeed);
Here is the full Script:
#pragma strict
var maxAnimationSpeed = 2F;
var backwardSpeed = 1F;
var forwardSpeed = 1F;
var rightSpinSpeed = 1F;
var leftSpinSpeed = 1F;
var Idle : String;
var forward : String;
var backward : String;
var left : String;
var right : String;
private var targetRigidbody : GameObject;
private var xforward : boolean;
private var xbackward : boolean;
private var xleft : boolean;
private var xright : boolean;
private var relative : Vector3;
function Start () {
animation.wrapMode = WrapMode.Loop;
targetRigidbody = transform.parent.gameObject;
}
function Update () {
reset();
relative = transform.InverseTransformDirection(targetRigidbody.rigidbody.velocity);
Debug.Log(relative);
if(relative.z > relative.x && relative.z > 0.01){
if(relative.x >= 0.5){
if(!xright){
if(xleft)
xleft = false;
if(xforward)
xforward = false;
if(xbackward)
xbackward = false;
animation.CrossFade(right);
xright = true;
}
if(animation.IsPlaying(right))
animation[right].speed = Mathf.Clamp(Mathf.Abs(relative.z) / rightSpinSpeed, 0, maxAnimationSpeed);
} else if(relative.x <= -0.5){
if(!xleft){
if(xright)
xright = false;
if(xforward)
xforward = false;
if(xbackward)
xbackward = false;
animation.CrossFade(left);
xleft = true;
}
if(animation.IsPlaying(left))
animation[left].speed = Mathf.Clamp(Mathf.Abs(relative.z) / leftSpinSpeed, 0, maxAnimationSpeed);
} else {
if(!xforward){
if(xleft)
xleft = false;
if(xright)
xright = false;
if(xbackward)
xbackward = false;
animation.CrossFade(forward);
xforward = true;
}
if(animation.IsPlaying(forward))
animation[forward].speed = Mathf.Clamp(Mathf.Abs(relative.z) / forwardSpeed, 0, maxAnimationSpeed);
}
} else if(relative.z < relative.x && relative.z < -0.01){
if(!xbackward){
if(xleft)
xleft = false;
if(xright)
xright = false;
if(xforward)
xforward = false;
animation.CrossFade(backward);
xbackward = true;
}
if(animation.IsPlaying(backward))
animation[backward].speed = Mathf.Clamp(Mathf.Abs(relative.z) / backwardSpeed, 0, maxAnimationSpeed);
}
}
function reset () {
if(relative.x >= -0.4 && relative.x < 0.4 && relative.z >= -0.4 && relative.z < 0.4){
if(!animation.IsPlaying(Idle)){
animation.CrossFade(Idle, 0.5);
if(xleft)
xleft = false;
if(xright)
xright = false;
if(xbackward)
xbackward = false;
if(xforward)
xforward = false;
}
}
}
Comment
Is this too hard to figure out or are you all just ignoring this? At least ONE answer wouldn't hurt.