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'm working on a platforming game with tile based levels. I store the collision model for my tileset in an array.

This is how the collision model for a 4x4 tilesheet would look like (I can't post pictures yet so this link will have to suffice: Tileset example). The red dots are the vertices of the b2ChainShape.

When I load a level, I look up the collision model for each tile and create a b2Body at the corresponding place. The problem is that between the tiles, my character can experience a "bump" because it gets stuck on the edge of the shape of the next tile's body.

Is there an existing algorithm to connect the bodies of neighbouring tiles to a single b2ChainShape? Or should I ditch the idea of tile-based collision models all together and simply create the collision model for the whole map with the Tiled map editor? I don't create the the collision map with the Tiled map editor at the moment, because it is very time consuming for slopes and hills.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You could just walk through your tiles in a top-left-bottom-right way, then create an outline for each of the connected tiles programmatically, similar to the marching squares algorithm: http://en.wikipedia.org/wiki/Marching_squares

Each time a piece of the "countour line" changes direction, you create an edgeshape for it. You can now set so called ghost vertices for these edge shapes; vertex0 for the current edgeshape to vertex2 of the previous edgeshape and vertex3 of the previous edgeshape to vertex1 of your current edgeshape, this process is explained here: http://www.iforce2d.net/b2dtut/ghost-vertices

This would basically give a hint to box2d how to resolve the collision response to contact points between the different edgeshapes.

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.