I just got started with animator and I got into a lil problem here.
I started a 2D Jump n run engine.
The char has animations for jump, walk and stand.
I pass two float Parameters to my AnimationController
xVelocity
yVelocity
When xVelocity is != 0 I want the Player to have the walking animation
When yVelocity is < 0 or > 0 (you could say “does not equal 0”) I want the jump animation to play.
The problem is …I can not use a “Equals” or “Not Equal” condition on float.
Is my approach wrong? …I don’t quite get why I can not check if a float is equal / not equal to some value…however…with INT I can check this
for the transition idle to walk, create 2 condition
xVelocity Greater 0.1
xVelocity Less -0.1
for jump it almost the same thing too
yVelocity Greater 0.1
xVelocity Less -0.1
There is no ‘Equal’ or ‘Not equal’ because float equality is not well define on the floating point unit, you can always have rounding error that make you believe that the current value is 0 but in fact it close to zero which make the condition fail even if what you see in the editor is 0.
There IS a Mathf.Approximately() function though, so I’m not sure why Unity couldn’t use that in the background for an Equals comparator in the animation, rather than make us have to do some jank like this~
(Yes, I know this is a DEEP necro, but this thread is the first thing that pops up when you search for this issue on Google)