3
\$\begingroup\$

I am making a simple grid-tile-based platformer with basic physics.

I have 16px tiles, and after playing with gravity it seems that to get a nice quick Mario-like jump feel, the player ends up moving faster than 16px per second at the ground.

The problem is that they clip through the first layer of tiles before collisions being detected. Then when I move the player to the top of the colliding tile, they move to the bottom-most tile.

I have tried limiting their maximum velocity to be less than 16px but it does not look right.

Are there any standard approaches to solving this? Thanks.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Did you mean 16px per frame instead of 16px per second? \$\endgroup\$
    – msell
    Sep 4, 2012 at 9:54
  • \$\begingroup\$ Just like msell asked... If the acceleration is 16px/s, and you check for collisions multiple times per second (or every frame), then it shouldn't be a problem. \$\endgroup\$
    – Marton
    Sep 4, 2012 at 10:00

2 Answers 2

5
\$\begingroup\$

The easiest approach is to check for collisions more often. This approach separates into two methods:

  • [most optimal, harder to implement] Check for collisions at least once per frame and after each N pixels (usually half of a tile) of movement.
  • [least optimal, easier to implement] Split the movement vector into N parts (depends on level design, could even be 16 and more), check for collisions after each addition of a part.
\$\endgroup\$
5
\$\begingroup\$

You could use movement subdivision. If you have an object with a bounding box with a height of 50 and it moves 300 pixels in height that frame then you can move it 6 times 50 pixels and check each time if there is a collision.

A small optimization to this technique is to draw a second bounding box from the start position to the end position of the bounding box and check if anything intersects with this. If not you can skip the movement subdivision test and just move it once.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .