Simpler collision detection?
Author |
Message |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Jan 24, 2009 1:26 pm Post subject: Simpler collision detection? |
|
|
I thought of an interesting way to do collision detection. I'm sure it's been done before, but I'd like some validation for my idea. It was inspired by the DWITE maze questions.
I would make 2 maps, one a regular picture, the other ASCII. Basically, I would divide the map into large sub-coordinates, each corresponding to one of the ASCII characters. The player would still have pixel-by-pixel movement, but collision would be based on perhaps 20X20 blocks. A quick mathematical equation to see what sub-coordinate the player is in, and then a check over the ASCII map of where walls are. This would also simplify the AI.
The only drawbacks I see with this is that the collision would be square, and each wall would have to be 20X20 pixels wide. No slopes or anything. Though I suppose special characters would could be used to represent slopes, with some extra coding/checking for them. Special items or ground types (like springy platforms) could be coded in very easily. This would be far more efficient than checking every wall every loop (I know, most games they use temporal coherence, (wiki)but I'm keeping it simple). It would allow for far more interesting maps than checking color, and is just a cool way of doing it. AI could be simplified as well (as shown by DWITE). It would also remove the need to code in the coordinates of every object. I believe the advantages outweigh the disadvantages, until I stop being lazy and start doing things right.
Tell me what you think? Is it feasible? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dan
![](http://wiki.compsci.ca/images/archive/3/3c/20100325043407!Danspic.gif)
|
Posted: Sat Jan 24, 2009 2:27 pm Post subject: RE:Simpler collision detection? |
|
|
Not only is it fesible it's how most simple tile based top down 2d game work. Alot of the RPG makers you can find online use this system as well as alot of the old 2d RPGs and action games.
My first computer sci ISU (it was a 2d top down RPG in turing) used this method (or something like it). I think there are even some tuorials and examples for making such a system on this site.
It works quite well if you make the tiles (the boxes in the gird) with the idea that you can either walk on all of it or none of it in mind.
You can also asign more properies to each tile then walk on or not, such as make some tiles warp poitns that take the player to a new map.
It's not the best method to use but it is one of the easyests if you want the system to be generic enought that you don't need to code each wall, etc. It also lets you make an editor that can make maps for your game so you can add content with out coding. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
|
|
|
![](images/spacer.gif) |
|
|