x


Animation Script Help

I have wrote this script which kind of does what I want it too; I want it to play an idle animation if nothing is being pressed play a walk animation when w or s is pressed, play a shoot animation when the LMB is clicked and play a reload animation when r is pressed. All this works but the shoot animation sort of delays which I dont want. Can anyone help me out with this?

this is my script,

function Start () {

animation.wrapMode = WrapMode.Loop;

animation["idle"].speed = 0.2;

animation["walk"].speed = 1;

animation["reload"].speed = 1;

animation["shoot"].speed = 2;

animation["shoot"].wrapMode = WrapMode.Once;

animation["reload"].wrapMode = WrapMode.Once;

animation["shoot"].layer = 1;

animation["reload"].layer = 2;

animation.Stop();

}

function Update () {

if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)

  animation.CrossFade("walk");

else

  animation.CrossFade("idle");

if(Input.GetButtonDown("Fire1"))

  animation.CrossFade("shoot");

if (Input.GetButtonDown("r"))

   animation.CrossFade("reload");   

}

more ▼

asked Nov 30 '11 at 07:19 PM

Dreave gravatar image

Dreave
122 82 94 96

What do you mean delayed? It takes time before it begins? Does it do this for all the animations?

Nov 30 '11 at 10:48 PM zinnfandel

if I click the LMB it plays the animation but then I have to wait a couple of seconds before I can do it again.

Dec 01 '11 at 04:39 PM Dreave
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first

Shooting must have instance response.I think your shoot animation is being delayed because of crossfade or transition what ever you http://say.So, stop any previous animation instantly before using shooting animation.

if(Input.GetButtonDown("Fire1")){animation.Stop();animation.Play("shoot");}

if(Input.GetButtonDown("r")){animation.Stop();animation.CrossFade("reload");}

more ▼

answered Dec 01 '11 at 07:46 PM

suruz@kento gravatar image

suruz@kento
76 1

this works great thanks!

Dec 01 '11 at 08:22 PM Dreave
(comments are locked)
10|3000 characters needed characters left
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:

x5077
x3785
x3737
x1952

asked: Nov 30 '11 at 07:19 PM

Seen: 1237 times

Last Updated: Dec 01 '11 at 08:22 PM