- Home /
Animations Not Working
Howdy,
There has been a problem in my game for about two weeks now and it has been driving me insane. I have a BasicAnimations javascript I wrote that is supposed to play a walking animation when walking, and two jumping animations, one after another, when jumping. The problem is that when I'm doing a running jump, none of the animations play when the jumping animations are supposed to play. When I'm not doing a running jump and just jumping up and down, the jumping animations play regularly. Like I've said, I've been studying this script for two weeks, and I still don't know how to solve it. I know it has something to do with the jumping animations and walking animation playing at the same time, but I'm not sure how to fix it. I've tried everything, and I am tearing my hair out. Thanks.
#pragma strict
var grounded : boolean;
grounded = true;
function Update () {
if (Input.GetAxis("Horizontal") && grounded == true) {
animation.Play("walk");
}
if (Input.GetAxis("Vertical") && grounded == true) {
animation.Play("walk");
}
if (Input.GetButtonDown("Jump") && grounded == true) {
grounded = false;
animation.Play("jump start", PlayMode.StopAll);
animation.PlayQueued("jump end", QueueMode.CompleteOthers);
}
if (grounded == false) {
animation.Stop("walk");
grounded = true;
}
}
Answer by thevraptor · Jun 14, 2014 at 07:40 PM
I have now fixed this problem using coroutines. Thanks for your help though!
#pragma strict
var grounded : boolean;
var random : boolean;
grounded = true;
random = false;
function Update () {
if (Input.GetAxis("Horizontal") && grounded == true) {
animation.Play("walk");
}
if (Input.GetAxis("Vertical") && grounded == true) {
animation.Play("walk");
}
if (Input.GetButtonDown("Jump") ) {
animation.Play("jump start", PlayMode.StopAll);
grounded = false;
animation.Stop("walk");
animation.PlayQueued("jump end", QueueMode.CompleteOthers);
Grounded ();
}
}
function Grounded () {
yield WaitForSeconds(1);
grounded = true;
}
Answer by MetalTux99 · Jun 07, 2014 at 07:39 PM
I think problem is a overlap of animation: if (grounded == false) { animation.Stop("walk"); grounded = true;
I had the same problem and I found an only solution, an orrible solution: delete "animation.Stop("walk")" and try to change the name of the animation so that Unity can't find the animation "walk" and it plays only the other one. Console will shows errors but ignore it. I'm sorry for my bad English.
yes but then i wont be able to play the walking animation when walking