Sign in to follow this  
walnut100

Need guidance - AABB collisions

Recommended Posts

Hey everyone,

So I've been working on my game for a little while now, specifically the evil of collision detection, and after a lot of studying and a lot of work I got collisions between two AABBs working. Yay!

The problem here though is corners. I'm using this for a Mario style platformer and size doesn't seem to matter with this, although with smaller objects it becomes more detrimental to gameplay. I can jump through corners (approach from the left moving up, go straight through the corner like its not there) and sometimes if I hit it just right I can penetrate the rectangle through corners.

The problem isn't tunneling because even at high speeds if I hit it flat (ie if I'm under a platform and go straight up) then it works perfectly. But if I barely hit the edge then it pushes my character off and he falls straight to the ground.

Is there a good way to fix this? I know swept tests are expensive but if it'll fix the problem then I can use those, or maybe I could adjust the tolerance of how it catches collisions to favor resolving on the y-axis? That seems like it could lead to big problems though.

Any advice is much appreciated. And I'm sorry if what I'm asking isn't too clear, my roommate's being loud and its hard to gather my thoughts with a lot of noise

Share this post


Link to post
Share on other sites
Quote:
Original post by walnut100
Is there a good way to fix this? I know swept tests are expensive but if it'll fix the problem then I can use those, or maybe I could adjust the tolerance of how it catches collisions to favor resolving on the y-axis? That seems like it could lead to big problems though.

Sweep tests are more expensive, but sometimes cheaper methods just don't do what you need. It may not be much of an issue if you're doing proper culling though. Take the bounding box of your object's current area and it's future area and check if any objects collide with that. If they don't collide with that bounding box, then you don't need to perform the more expensive sweep test either. If you store your static objects in a grid or quadtree, checking which objects collide with the bounding box should be pretty fast, too.

Share this post


Link to post
Share on other sites
Well if you think that swept tests (with the proper optimization logic like you described of course!) will do the trick then that's good enough for me.

Thanks a million!

Share this post


Link to post
Share on other sites
Before spending a lot of time with sweep tests, try something simpler like using next frame's *possible* position as the center for your bounding box (current_position + velocity). If the collision happens, change the velocity somehow.

Share this post


Link to post
Share on other sites
Hi,

Before going for the more expensive test, first make sure you absolutely need it. Maybe there's a bug in your code you may not be aware of. Maybe its something to do with floating point round-off errors or some other bug you may have missed.

Generally, for a platform game as a basic collision strategy, using AABBs should suffice and if your collision code is good you should never be able to get *INSIDE* another AABB. That seems entirely wrong.

If you could post some code for the collision tests and the updating of the character's motion it might help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this