- Home /
Problem with changing animations using int values
So I have a problem with a possible Unity animation problem. I made an (int) in the animator parameter. In the code, I assigned the int values as idle=0, walking=1, jumping=2.
However, everytime I load the game, it starts fine, with the state (int) value being 0 (which means it's idle). However once I started moving left or right, the int value immediately switches to 2, but the character should be walking, not jumping. I don't think it's the transition problems in the animator, since they should be set correctly (I double checked). It probably is something to do with the code.
This is the whole code, which programs the character's movements. I followed this tutorial: https://www.youtube.com/watch?v=65E-q0JxYwU I am just a beginner, so help is really appreciated
Answer by AaronBacon · Aug 17, 2021 at 05:29 PM
The problem is on Line 55, you've written:
⠀
if(rb2.velocity.y > .1f) ;
{
state = MovementState.jumping;
}
⠀
Note the semicolon ; after the if statement. That immediately ends the if statement, then proceeds to run whats meant to be the content of the if statement regardless. So all you need is to remove the Semicolon:
⠀
if(rb2.velocity.y > .1f)
{
state = MovementState.jumping;
}
⠀
Welcome to the world of programming, where everything breaks because of 1 misplaced character.
⠀
It is worth noting that Visual Studio has underlined it in green and I'm assuming is giving you a warning because it can tell you probably didn't mean to do that.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can i use any imported model(for example Crysis Nanosuit) instead of mecanim rigged model? 0 Answers
Floating boss Hands, can't move bones of hands for attacks 0 Answers
There is a problem with the code, possibly the animator as well... Please help? 1 Answer
2D Animation does not start 1 Answer