2
\$\begingroup\$

My team and I are developing a 2D platformer with C++/SDL/OpenGL, and we already defined a collision system, but we have a problem checking collisions with the tilemap.

The tiles of the tilemap are 32x32, so we try to define that the max speed in X and Y of the player it's less than 32 because in this case we found the problem that if the speed it's bigger than the tile size, when checking the collisions the position it's updated with the speed which it's more than 32, so in that case, the position skip a tile which causes a huge problem for verification, so at the momento we limit the X and Y speed to 30, but we don't know how make the speed bigger than the tile size without losing the complete collision detection with some possible tiles that may be skiped.

Thanks a lot

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The Easiest way is to update your world twice(or more) every cycle. using this method you can increase your max speed 2 or more times.

The more Universal way to do it but is to check collision of the shape generated by the moving object, with all the tiles. something like the picture below while red box moves collision is checked for every square in map and the blue area (which is a polygon generate by convex hull algorithm):

collision sample

physic engines usually have a support for such a feature, to check continues space for movement. for example in box2d there is a member (isBullet) which indicates if engine should use continues movement checking.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks a lot for the answer, I will checkout that algorithm and tell you about it later. \$\endgroup\$
    – oscar.rpr
    Commented Dec 5, 2011 at 14:35
  • \$\begingroup\$ Thanks for the answet. I already use a sweep test algorithm which it's working really greay, anyhow I will have in mind this algorithm for future projects. \$\endgroup\$
    – oscar.rpr
    Commented Dec 10, 2011 at 14:02
  • \$\begingroup\$ well, what I said was just using sweep algorithm for any polygon, or at least how I know sweep is implemented for none trivial shapes. \$\endgroup\$
    – Ali1S232
    Commented Dec 10, 2011 at 17:24

You must log in to answer this question.

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