Basically I have a script that plays its animation according to the buttons being pressed. For example,
Doing nothing = Idle Animation
Walking = Walking Animation
Walking + Sprint = Sprint Animation
The script works perfectly, The only Problem is that whenever i go from walking or sprinting to Idle, The walking or sprint animation continues to play for a brief sec or so and THEN changes to the idle Animation. This only happens when i go to the Idle animation. I want it to changes instantly, like it does from walking to sprinting or vice versa.
Heres my script :
var PlayerState : float;
var PlayerAnimSec : GameObject;
var PlayerMotor : CharacterMotor;
var WalkingSpeed : float = 6;
var SprintSpeed : float = 9;
function Update (){
PlayerStateController();
PlayerAnims();
}
function PlayerStateController(){
if((Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0)){
if(Input.GetButton("Sprint")){
PlayerState = 2;
}else{ PlayerState = 1;}
}else{ PlayerState = 0;}}
function PlayerAnims(){
if (PlayerState == 0){
PlayerAnimSec.animation.CrossFade("IdleAnimation", 0.4);
}
if (PlayerState == 1){
PlayerAnimSec.animation.CrossFade("WalkingAnimation", 0.4);
PlayerMotor.movement.maxForwardSpeed = WalkingSpeed;
PlayerMotor.movement.maxBackwardsSpeed = WalkingSpeed;
PlayerMotor.movement.maxSidewaysSpeed = WalkingSpeed;
} if (PlayerState == 2){
PlayerAnimSec.animation.CrossFade("SprintAnimation", 0.4);
PlayerMotor.movement.maxForwardSpeed = SprintSpeed;
PlayerMotor.movement.maxBackwardsSpeed = SprintSpeed - 2;
PlayerMotor.movement.maxSidewaysSpeed = SprintSpeed;
}
}
Thanks for the help!