2d tile collisions against 'larger' objects?

Started by
7 comments, last by justcolorado 12 years, 4 months ago
Hello, I have been following http://www.metanetsoftware.com/technique/tutorialB.html and http://www.codezealot.org/archives/55, which describe how to manage 2d collisions by using a 'Separating Axis Theorem'.

I have the basic functionality working, and I would now like to experiment in how to use it in my game concept. The problem I am running into, is how to figure out 'which tiles' I should be checking against, for objects that are larger than the tile size.

Here is an example image to illustrate:
example_1.jpg


Previously, the user was smaller than a tile, so it could fit inside a tile, and I could just check against the corners to determine which tiles to check for collisions, but now that I want to use objects that are larger than the tile size, I am not sure how to figure out which tiles to check for collision information.

I suppose I could still check for 'corners', but what about in situations where the corners are outside of collision area, but the center is not (like the vertical wall in the center of the drawing) ??

Does anyone have any tutorials or concepts on how to work with this? Basically objects that are larger than the tile size...

One idea just came to me, I could cut the larger objects down into 'tile size chunks', but that doesn't seem very efficient.

Any ideas? Please help if you can, thank you!

Bunzaga
Advertisement
Ahh, I may have already found a solution, but I am still open for suggestions.

Rather than use the objects 'corners', I could do something like a path finding algorithm, starting with the center of the object as the first 'node'. For each tile, check if the objects minX/Y, and maxX/Y lie within the tiles boundaries. If it does, then I came to the edge of the object. If it doesn't then I add the neighboring tiles to the list.

If there is a better way, please let me know! :)
* Form the AABB for each object
* Intersect AABB of tiles with each objects AABB
* Those are the tiles to check

:)
Oh duh, LOL. I wonder why I was making it more difficult than it was!

So just get min_x/y, max_x/y for each OBB, and check all tiles within that range to see if they are intersecting. If they are, then check those tiles for collisions.

Here is a modified version of the image to make sure I understand:
example_2.jpg

Oh duh, LOL. I wonder why I was making it more difficult than it was!

So just get min_x/y, max_x/y for each OBB, and check all tiles within that range to see if they are intersecting. If they are, then check those tiles for collisions.

Here is a modified version of the image to make sure I understand:
example_2.jpg



Sure... Any objects overlapping the same tile should be collision tested further :)
Hey thanks again wildbuny! I have a proof of concept working (almost). I just need to work in removing the tiles that aren't intersecting at all:
wip_1.jpg


The blue 'stars' represent the objects min/max AABB. The red tiles are the ones added to the initial 'check_list'. The next step would be to get rid of the tiles that are not overlapping.

I just wanted to let you know, your help is appreciated, and is in use. :)

Bunzaga

Hey thanks again wildbuny! I have a proof of concept working (almost). I just need to work in removing the tiles that aren't intersecting at all:
wip_1.jpg


The blue 'stars' represent the objects min/max AABB. The red tiles are the ones added to the initial 'check_list'. The next step would be to get rid of the tiles that are not overlapping.

I just wanted to let you know, your help is appreciated, and is in use. :)

Bunzaga


No problem - just a note: typically, I never bother to do such pruning of the unused tiles - the broad-phase is only supposed to be a rough estimate anyway :)
Yea, I was kind of thinking the same thing... I mean what will 1-2 or so extra tiles do anyway? In the final SAT system, I don't think it will have that much overhead, and there will only be up to around 3-4 enemies + player, so it's not like I am under extreme pressure to optimize. I guess it's just that OCD part of me trying to over optimize before I even have to.

* Form the AABB for each object
* Intersect AABB of tiles with each objects AABB
* Those are the tiles to check

:)


Thanks. That answers a question I was about to post.

My Projects: - www.repulse.com

This topic is closed to new replies.

Advertisement