3
\$\begingroup\$

I will use game called "Project Zomboid" as an example. Here is a pic how does it look >

enter image description here

How should I handle player's collision with walls constructed like that? It's easy to handle walkable and not walkable tiles for player, but this is different and I have no ideas how to solve this problem. Any tips?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The walls are just a visual aspect of the collisions. The tiles on the ground are where the collision detection is happening. \$\endgroup\$ – MichaelHouse Oct 29 '13 at 22:33
4
\$\begingroup\$

Store flags for the edges of tiles, not the whole tiles. For instance, the "Southeast Wall" tile might have the flags SouthWall and EastWall set. When doing collision tests, check the boundaries you're crossing, not the whole tile.

Alternatively, for even more flexibility, store both tiles (floors) and the boundaries/walls in separate or interleaved arrays. If interleaved, you'd have walls/boundaries in the even spaces (0, 2, 4, 6, etc.) and tiles in the odd spaces (1, 3, etc.) with every map being an even size (every tile is surrounded by boundaries). This works if your tiles and boundaries are roughly the same in terms of data. Separate structures works just fine, too. The advantage to this approach is that you can have tile/floor data separate from wall data and each wall is its own entry, so you can more easily mix-and-match walls and floors.

A further simplification is to still have tiles, with each tile now have two wall fields, say upper-left and upper-right (the other two sides are the walls from the tiles below).

This approach has been used in some non-isometric 3D tile-based games as well (think Dungeon Master, Grimrock, Stonekeep, etc.) that wanted to encode data in the walls in addition to data in the floors, e.g. to have a cubby in the north wall and a separate cubby in the east wall but no cubby and walkable floor on the other side of the walls.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks for clear and detail answer. I understand it now. \$\endgroup\$ – Tom Oct 30 '13 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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