Y-speed gets an odd value when standing

stefan

  • *
  • Posts: 2263
Hey all, long time no see!

I came acros the following issue where my Y-speed gets an odd value whenever the tiles span over the width of my actor. When I move my actor even a pixel over the edge, the Y-speed gets to a nice solid 0. This is the first time im seeing this, so I dont know where to start looking. Ive double checked all collision settings, and both the tiles and actor has a simpe box collider.

Only thing I can think of is that the tile size is 20x20, and the seemingly 3 tiles that im touching in the second screenshot, are actually 6 tiles.

Tia!

merrak

  • *
  • Posts: 2738
It looks like a numerical precision error to me. There's probably not going to be anything you can do about it. Floating point arithmetic is subject to these kinds of quirks. The arithmetic, in this case, is likely where Box2D is computing the new y-speed after applying gravity and also checking for collisions. It's usually best to not use = to compare two floating point values. To check if the actor is not moving up or down, rather than comparing its y-speed to 0, compare the absolute value of its y-speed to some very small value "epsilon", such as 0.00001.

stefan

  • *
  • Posts: 2263
Makes sense, but its odd since I never saw this before. Thanks!