[SOLVED] X Velocity of player weird on certain parts of collision (2D)

So I have a 2D platformer with a simple level generator (takes a .png, reads the image and spawn tiles accordingly) it at first had some bugs but with some help I solved them, everything worked fine for a while but when I started editing the image and adding some more tiles to it, the new tiles acted weird: the X velocity of
my player it turns into a weird number? Is there any logical explanation?

9817374--1410807--weirdcollision.png

The value is being displayed in scientific format. The e means x10 to some power.
The snapshot doesn’t show the whole exponential value though. It could be -8.77e-09 which is: 0.00000000877. That is pretty much 0.

Apparently it is something like 0.0000000877 which is, like you said, basically 0. But the problem is: the players running animation gets activated when the X velocity isn’t 0 so it activates.

You could change the if statement to check if the absolute velocity is bigger than let’s say 0.1 for example. It would be something like this:
If (Mathf.Abs(xVelocity) > 0.1f)
{
//Play run animation
}
else
{
//Play idle animation
}

Thanks this works!

No problem, good luck with your project!

1 Like

Thanks!

1 Like