- Home /
Trouble with Turning Animation
Hello,
I'm scripting a character with a turning animation, but there's a problem with it. I need the animation to play completely and then face the turning direction, but it only plays the animation as long as the Key is held down, and that doesn't even work if the rotation script is functional.
Can anyone offer guidance?
function Update () {
if(charController.isGrounded == true)
{
transform.eulerAngles.y += Input.GetAxis("Horizontal");
// Calculate the movement direction (forward motion)
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if(Input.GetAxis("Vertical") > .1){
animation.CrossFade("Run");
}
else if(Input.GetAxis("Vertical") < -.1){
animation.CrossFade("Backwards");
}
else if(Input.GetAxis("Horizontal") > .1){
animation.CrossFade("TurnRight");
}
else if(Input.GetAxis("Horizontal") < -.1){
animation.CrossFade("TurnLeft");
}
else{
animation.CrossFade("ReadyIdle");
}
}
Answer by DaveA · Aug 24, 2011 at 04:35 PM
It's probably doing the cross to ReadyIdle as soon as you let up on any key. You may need to yield for the duration of the animation before allowing that idle to play.
How do I do that by code?
I don't think that the Wait function works for animations unless timed.
else if(Input.GetAxis("Horizontal") > .1){ PlayTurnRight();
}
function PlayTurnRight(){
animation.CrossFade("TurnRight"); yieldWaitForSeconds(animation["TurnRight"].clip.length);
}
I tried, but no success
Answer by luckruns0ut · Aug 24, 2011 at 07:51 PM
how about an if(transform.rotation) { animation.play("turn"); }
This isnt an actual line of code im just trying to give you an idea. its supposed to be if the player rotates at all it plays that animation.