Skip to main content
1 of 2
Leftium
  • 4.4k
  • 3
  • 25
  • 30

OK, I figured out why the XNA AppHub platformer demo doesn't have the "jumping" bug: the demo tests the collision tiles from top to bottom. When up against a "wall" the player may be overlapping multiple tiles. The resolution order is important because resolving one collision may also resolve other collisions (but in a different direction). The onGround property is only set when the collision is resolved by pushing the player up on the y-axis. This resolution will not occur if the previous resolutions pushed the player down and/or horizontally.

I was able to reproduce the "jumping" bug in the XNA demo by changing this line:

for (int y = topTile; y <= bottomTile; ++y) 

to this:

for (int y = bottomTile; y >= topTile; --y) 

(I also tweaked some of the physics-related constants, but this should not matter.)

Perhaps sorting bodiesToCheck on the y-axis before resolving the the collisions in your game will fix the "jumping" bug. I suggest resolving the collision on the "shallow" axis of penetration, as the XNA demo does and Trevor suggests. Also note the XNA demo player is twice as tall as the collide-able tiles, making the multiple collision case more likely.

Leftium
  • 4.4k
  • 3
  • 25
  • 30