ry bout all these newbie questions guys lol. Anyways, I have these animations for walking and sprinting. I have it so when u press the w key it loops and when u let the button go. Ok so that works perfectly, but when I tried to do that with sprinting it doesn’t run either animation. What’s up with that? Here’s my code. It’s a modify of the Character motor script on the FPC:
var walkSpeed: float = 7; // regular speed
var crchSpeed: float = 3; // crouching speed
var runSpeed: float = 20; // run speed
private var chMotor: CharacterMotor;
private var tr: Transform;
private var dist: float; // distance to ground
function Start(){
chMotor = GetComponent(CharacterMotor);
tr = transform;
var ch:CharacterController = GetComponent(CharacterController);
dist = ch.height/2; // calculate distance to ground
}
function Update(){
var vScale = 1.0;
var speed = walkSpeed;
if (Input.GetKey("left shift") || Input.GetKey("right shift")){
if (Input.GetKey(KeyCode.W))
{
speed = runSpeed;
GameObject.Find("FPS_m16").animation.Stop("Walking");
GameObject.Find("FPS_m16").animation.CrossFade("Sprinting");
}
}
if (Input.GetKey("left shift") || Input.GetKey("right shift"))
{
GameObject.Find("FPS_m16").animation.Stop("Sprinting");
}
if (Input.GetKey("c")){ // press C to crouch
vScale = 0.5;
speed = crchSpeed; // slow down when crouching
}
if (Input.GetButtonDown("Walk")){
GameObject.Find("FPS_m16").animation.CrossFade("Walking");
}
if (Input.GetButtonUp("Walk")){
GameObject.Find("FPS_m16").animation.Stop("Walking");
}
chMotor.movement.maxForwardSpeed = speed; // set max speed
var ultScale = tr.localScale.y; // crouch/stand up smoothly
tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
}
Thanks!