2d collision detection Q: bounded box


#1

hi all.

i’m still busy with a 2D side scroller on applet platform.

I was wondering: I have started collision detection on objects. I don’t need any spatial partitioning when using the bounded box algorithm, right? Wouldn’t it be wasteful since bounded box is already so efficient? There is no other way to improve cost other than bounded box? thanks, i’m new at this so I don’t know too much about it.

thanks.


#2

Kinda depends on the number of objects in your game. If you’re making an Asteroids clone - go right ahead, but something like Zelda or Mario I would consider a Tile-system.


#3

I already have a tile-system. The game is tile-based like mario. What I am talking about is the enemies crashing into the player (not checking on which tile the player is). I use standard bounding box for this. Just wondering if any kind of additional spatial partitioning could improve the speed. My thought is not, but i don’t have much experience with collision detection algorithms.

thanks.


#4

I would create some kind of border/box for each object on the screen (in this case the border of your tile). If the border of the player character crosses/touches/intersects with the border of an enemy, execute some form of player-gets-hit code or something.

This could be done with some simple if-then-else statements. You’ll just have to check all the borders of the objects which are visible in the viewport (you can leave the part of the level that isn’t visible alone).

If you used arrays, structures and/or classes to store object information, this all could easely be done with a for-loop.

edit: you can also check if the player is walking into a wall or something this way, using the borders of a brick tile for example.


#5

thanks for reply.

I’m actually already using a kind of simple armature (segment of lines forming a polygon of collision area for each object), however my polygon is a rectangle. So I basically decrease that image collision area and have more freedom for animation. What you say is what i already implement (kind of). Thanks for your reply. I think my question wasn’t very clear, sorry.

I don’t need any screen division further than what I already do (check only for objects onscreen). It fast enough. :slight_smile:


#6

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.