jbump icon indicating copy to clipboard operation
jbump copied to clipboard

Small sizes result in missed collisions

Open TheTwitchy opened this issue 2 years ago • 1 comments

I've noted a possible issue that we may want to add to the documentation, so that others can be aware.

Essentially, when using entities sized at about 1.0f (width and/or height) or smaller, or using small changes in position over time (speed of 1.0 * deltatime), the collision calculations will sometimes incorrectly "miss" the collision, I suspect because the change in position is not significantly different from zero (even if the rendering engine can pickup the difference).

For me, this resulted in rendering bugs where an entity would rapidly shift back and forth in almost the same spot over several frames while colliding with another entity. Initial investigations showed that the collision would not be reported by JBump in every other frame. Further digging showed that the Minkowski difference in Rect.rect_getDiff() was an exponentially small number in the returned rectangle X and/or Y variables (one example value was -7.748604E-7 in a frame with missed collisions) in frames that incorrectly missed collisions. I suspect that smaller sizes would result in more missed collisions per frame, but did not test this.

Overall, I think the framework is operating as intended, and there are no bugs here that need to be fixed, it's just a limitation of how computers compare numbers. However, we may want to add some documentation stating that using very small cell sizes and entities with small velocities can cause issues. Personally, I fixed this issue by apply a 10x modifier to all numbers passed to the collision engine to retain the view frame size I already have and use in a normal libGDX stage view.

Does anyone mind if I make changes to the docs warning of this limitation and stating the workaround?

TheTwitchy avatar Nov 04 '21 03:11 TheTwitchy