ive got a problem with my character. the ‘walk’ animation keeps playing after I have let go of the ‘walk’ key. here is my walk script -
animation["WALK"].layer=-1;
animation["REVERSE"].layer=-1;
animation["CROUCH"].layer=2;
animation["IDLE"].layer=-5;
var crouching: boolean;
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2){
animation.CrossFade ("WALK");
}else if(Input.GetAxis("Vertical") < -0.2){
animation.CrossFade ("REVERSE");
// Play animation backwards when running backwards
animation["REVERSE"].speed = Mathf.Sign(Input.GetAxis("Vertical"));
}else{
animation.CrossFade ("IDLE");
}
if(Input.GetKey("c")){
animation.CrossFade ("CROUCH");
}
}
and here is my walker script -
var speed = 6.0;
var RUNspeed=12;
//var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if(!Input.GetButton("Fire1"))
moveDirection *= speed;
else
moveDirection *= RUNspeed;
//if (Input.GetButton ("Jump")) {
//moveDirection.y = jumpSpeed;
//}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)