x


Animation stoping!!

Hi, This has been bugging me for a long time maybe you can help :) Okay so i have 3 animations (Idle,(ShootandReload << its all one animation because its a bolt action rifle),and walk,,, This is my code

function Update ()

{

if(Input.GetKey("w"))

    animation.Play("Walk");



else if(Input.GetKey("mouse 0"))

    animation.Play("Shoot");

    else 

    animation.CrossFade("Idle");

}

But when i have the Idle piece of code in there it goes messed up because the shoot/Reload doesn't run through the hole animation if you need more infomation check out this link to see what i meen :)
( http://www.youtube.com/watch?v=q2t32pMhHNQ )

Watch this video to see more :)

more ▼

asked Nov 07 '11 at 06:24 PM

UnityNeewb gravatar image

UnityNeewb
1 2 2 2

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

1 answer: sort voted first

You may want to rethink your logic. GetKey Returns true while the user holds down the key identified by name. So that means, if you fire, you typically will quickly press the "mouse 0" down and then let it up. When running through the update loop after you shoot, that means your else if statement is then false in the next update cycle, and it will go through the else statement where your idle animation is even though you want your shoot animation to finish.

By definition, CrossFade will IMMEDIATELY crossfade the current playing animation ( shoot ) and fade in the new animation ( idle ), at the default speed since you have not passed in a time value in the animation.CrossFade() arguments. So either you can try using PlayQueued, CrossFadeQueued, or lay out your logic differently to compensate for this change in animation states.

There are several other options that you can go with in animations, it's really an art in-and-of itself. There's blend weights, animation layers, checking if animation.IsPlaying(), and a slew of other things to get to your end point.

more ▼

answered Nov 07 '11 at 07:05 PM

dannyskim gravatar image

dannyskim
3.9k 5 7 19

(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x3929
x2057
x563
x26

asked: Nov 07 '11 at 06:24 PM

Seen: 745 times

Last Updated: Nov 07 '11 at 07:05 PM