- Home /
Something is wrong with my animation in Unity,
I'm trying to do an animation in unity, Changing it with script, and when i Jump and then press the arrow key it is fine, but if i jump while holding the arrow key it switches between the jump and the walking,
here is my code:
if (dirX != 0 && GameManager.instance.grounded) { anim.SetBool("walking", false); anim.SetBool("jump", false); //Debug.Log("grounded"); } else if (GameManager.instance.grounded && dirX == 0) { anim.SetBool("walking", true); //Debug.Log("Walking"); } else if (!GameManager.instance.grounded) { anim.SetBool("jump", true); //Debug.Log("Jumping"); }
what is wrong here?
Answer by Tsuki92 · Apr 21 at 01:04 PM
Hey mate, just noticed that you might have your booleans wrong, while reading your code i can see that you have when dirX != 0 you walking is set to false. which should be true. and the other way around in your Else if
Right now i have this:
if (!GameManager.instance.grounded && !GameManager.instance.flytoggle) { //Debug.Log("Falling or Jumping"); GameManager.instance.states = 2; }
else if (GameManager.instance.grounded && dirX == 0) { //Debug.Log("Idle"); GameManager.instance.states = 0; }
else if (GameManager.instance.flytoggle) { //Debug.Log("Flying"); GameManager.instance.states = 0; }
else if (dirX != 0)
{
GameManager.instance.states = 1;
}
The states logic is: 0 = Idle 1 = Walking 2 = Jumping
I must have copy and pasted wrong the first time
Alright i think i see the problem here.
if you are using Booleans in your animator then you need to set them in your code aswell. right now it looks like you might have a mix between them.
Animator:
You need a variable here named "state" the transitions should then be Idle -> walking = state == 1 walking <- idle = state == 0 any state -> jumping = state == 2 Jumping -> idle = state == 0
in your Movement script there should be code for your states ie:
Private Enum MovementState {idle, walking, jumping} Above start method.
If you want i can help you through Discord. reach out to me and you can share your screen.
BOop#1708
Sorry i am on a school laptop and can't access discord, plus i don't know what timezone you are in and don't want to intrude on your life :) i will try to do what you said, when i have time tonight
Answer by CodeMonkeyYT · Apr 21 at 09:12 AM
The problem is likely on how the Animation Transition is set up, do you have Exit time enabled? It should be disabled if you're using parameters. Enabling Exit time makes it automatically trigger the transition regardless of parameters.
Hello! I've watched some of your videos anyway, i have exit time off, and i changed down the little slope thing, and yeah. ALSO, sometimes when i review the animation it says that the sprite is missing, why is it doing that?
If you have Exit time disabled then the transition will never trigger automatically, only based on the parameters.
So if that's the case then the issue is with your parameter logic, look into the Animator while the game is running and look at the parameters, are they behaving as they should?
I have looked into the animator while the game was running and it says that the idle state is playing the entire time.
to idle from jump it checks if the parameter jump is false, to jump from idle it checks if the parameter jump is true, to jump from walking it checks if the parameter jump is true, to walking from jump it checks if the parameter walking is true, to idle from walking it checks if the parameter walking is false, to walking from idle it checks if the parameter walking is true,
i think that would be right
Your answer
Follow this Question
Related Questions
Need help with tool animations!! 1 Answer
Multiple Cars not working 1 Answer