• Advertisement
Sign in to follow this  

collision detection in side scroller

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I need some advice as to a collision detection algorithm for my game. I am writing a tile based side scroller and am really struggling with a collision detection algorithm. The way the tile map works is I have a 2*2 array (stored in the program as a pointer, so I can modify the size). This array is filled with numbers representing which tile to pick from. Some of these numbers should represent tiles that the character can't go through (such as blocks for the floor). The most obvious approach is the simple bounding box approach. Say something like test to see if after updating the position, any of the character will intersect with a tile that is no good. This would require somehow testing the border of the character against the tiles of the direction he is moving? The other problem is the fact that the character doesn't necessarily take up the entire bounding box. Because my tile size is 32 pixels by 32 pixels. By necessity for anything to work, the character's size has to be shaped as a multiple of this. It seems rather messy to try to test EVERY tile that the character takes up an whether or not this is interesecting with a "bad" tile or not. Anyway, I am sure many people have needed simple collision the way I am looking for.....Any ideas?!

Share this post


Link to post
Share on other sites
Advertisement
You could always create texture-specific bounding boxes; make up your own dimensions per texture if the character doesn't fit into the texture.

The other option is a per-pixel collision check, but I honestly don't feel like googling right now... I'll leave that up to you. If you're using a fancy 3D API it might be more difficult than simpler stuff.

Share this post


Link to post
Share on other sites
i have looked into pixel by pixel checking, but frankly it seems like it is too inefficient a process for what I am trying to do.

Can you be more explicit in what you mean by "texture specific bounding boxes"

Thanks !

Share this post


Link to post
Share on other sites
I believe what he means is that when you find out the location of your character on the map, you can find out what tiles he is intersecting with. Each of these tiles has their own texture, correct? Well, if one of the tiles is a circle (maybe a button of sorts?) does it make sense for it to doing square tile collision? Of course not. So because you know his location, and the texture that is drawn at that location, you can decide what kind of collision to do with that location.

Or at least thats how I interpret it. I could be wrong.

Share this post


Link to post
Share on other sites
ah....that makes sense.

my problem, however, is more with the bounding box around the character than that around the tiles. For the purposes of this game, I think the bounding box of the tiles should be sufficient. However, for the character it is much more complicated since he is much larger, so the mistakes are magnified---in a Mario game, if you land in animiated fire, it is obvious that you hit the fire, because part of your body has to be in the fire even if part of the tile with the fire is not actually fire---however if there were a space between Mario and the fire (i.e. the bounding box around mario wasn't computed right) then one would notice.

So to get correct bounding boxes, one thing I was thinking is that for different sequences animations, I could make different amounts of collision required. However, the whole thing just seems really messy and disorganized. Should I just make sure that all the frames of animation are of roughly the same dimension ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement