x


Animation problem in script

Sry 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!

more ▼

asked Dec 31 '11 at 09:45 PM

dylan56477 gravatar image

dylan56477
31 6 11 13

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5073
x3776
x224
x142
x82

asked: Dec 31 '11 at 09:45 PM

Seen: 466 times

Last Updated: Dec 31 '11 at 09:45 PM