- Home /
Walking animation problem.
hey guys i have a question here.
I Made an animation so that when i'm walking with my gun the gun moves up and down and it's good but i have an problem.
When i stop walking the gun keeps on making the animation, here's my script :
function Update()
{
if(Input.GetKeyDown("w"))
{
// Plays the walking animation - stops all other animations
animation.Play("walking", PlayMode.StopAll);
}
}
Does anyone know how to make it so that it stops when i stop pressing w?
I've heard about making it idle, making a new animation and then doing the same thing putting it in the weapon with another script blabla. But when i do that in the code should i do it like this? :
function Update()
{
if(Input.GetKeyDown("")) // <---- NOTICE I PUT NOTHING BETWEEN THE ""
{
// Plays the idle animation - stops all other animations
animation.Play("idleanimation", PlayMode.StopAll);
}
}
Thanks.
[ Javascript please. ]
Vince
Answer by ByteSheep · May 11, 2013 at 01:30 PM
function Update()
{
if(Input.GetKey("w"))
{
animation.Crossfade("walking");
}
else
{
animation.Crossfade("idle");
}
}
Its not working, when i put the idle animation in and update the script the walking animation kinda glitches and plays once but when i keep it pressed it like does it once and then nothing. Also the idle is working but now the walking isn't..
Well I updated the code a bit to show you how you would check to make sure that you only play the animation if it is not already playing. I highly recommend reading the docs on animations.
Thanks, i updated the code once again but its still not working, now my animations dont work. They do nothing.
Ok I updated the code again, note that you normally wouldn't check for a specific key being pressed, but rather whether the characters velocity is higher than a certain amount.
Remove the "&& !animation.IsPlaying("idle")" and " && !animation.IsPlaying("walking")" bits from the code.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Missile Firing Script Help 1 Answer
Animation play on input, else play idle animation. 2 Answers
Calling a C# function from a Javascript 3 Answers