Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
3  
Did you mean 16px per frame instead of 16px per second? –  msell Sep 4 '12 at 9:54
    
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. –  Marton Sep 4 '12 at 10:00
add comment

2 Answers

up vote 5 down vote accepted

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.
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.