Suggestions for collision detection ...

Started by
11 comments, last by tonyg 17 years, 2 months ago
Hi all,

I haven't logged on for a bit, but thanks for all your replies.

I apologize ( yet again ) because I think you are misunderstanding the question, the problem is not blocking tiles, I could block 1 whole tile should the contents be impassable( which probably wouldn't be too hard ), but the problem is, that I can't find a way to represent the actual CONTENTS of one tile. Even if I declared my tile map array to contain an array of tile objects, I would still have to represent the CONTENTS of a tile. ( the only way I can think is to brake it down into smaller pieces, or to draw / define a bunch of rectangles over the pre-rendered map to represent impassable areas ).

I have drawn each tile as 64x64 pixels in a bitmap. One tile has, for example, a river following down the middle, BUT there is STILL GRASS within the same tile, the problem is determining which part of the tile is grass, and which part water.

Looking at the solutions, they all seem to provide a way to only block the full tile, and not a portion of one. Sorry if I haven't understood a perfectly valid solution already posted,

and thanks for all your help, I appreciated it :)


-Lintford
Advertisement
I think I answered your question...
Maybe its not a perfect way to do it, but it should work...

You have a tile like this: (sorry.. programmers art)


If you would save tileObjects in the field array you could easy check how far you can "walk" on the tile by checking the offset of the "blockline".

For example you have a tile like the example picture above.
The attributes block_x would be set to 30 (because blockline is at px 30 of the tile) and block_y would be set to -1 so you know that the blockline is running vertical.

This method only works for tiles like this, If you have tiles like this

it will not work. In this case it might be an idea to store rectangle coordinates for the blocked area of the tile.

I'm not sure if this is an ideal method, because you maybe have to store some more information. But I'm pretty sure this would work :)

Cheers Zerd
... and depending on how big the map is I might still suggest the higher detailed walkability grid. (e.g. tiles 64*64, walkability 8*8). Alternatively, you have a seperate tilegrid the same size as the map with simple black/white shapes for walkability. (like some platform games)

This topic is closed to new replies.

Advertisement