Collision Resolution
- by ultifinitus
Hey all, I'm making a simple side-scrolling game, and I would appreciate some input!
My collision detection system is a simple bounding box detection, so it's really easy to implement. However my collision resolution is ridiculous! Currently I have a little formula like this:
if (colliding(firstObject,secondObject))
firstObject.resolve_collision(yAxisOffset);
if (colliding(firstObject,secondObject))
firstObject.resolve_collision(xAxisOffset);
where yAxisOffset is only set if the first object's previous y position was outside the second object's collision frame, respectively xAxisOffset as well.
Now this is working great, in general. However there is a single problem. When I have a stack of objects and I push the first object against that stack, the first object get's "stuck," on the stack. What's I think is happening is the object's collision system checks and resolves for collisions based on creation time, so If I check one axis, then the other, the object will "sink" object directly along the checking axis.
This sinking action causes the collision detection routine to think there's a gap between our position and the other object's position, and when I finally check the object that I've already sunk into, my object's position is resolved to it's original position...
All this is great, and I'm sure if I bang my head against a wall long enough i'll come up with a working algorithm, but I'd rather not =). So what in the heck do you think I should do? How could I change my collision resolution system to fix this?
Here's the program (temporary link, not sure how long it'll last)
(notes: arrow keys to navigate, click to drop block, x to jump)
I'd appreciate any help you can offer!