0
\$\begingroup\$

Currently I use AABB's to represent objects in my game engine, I resolve collisions between them by finding the shallowest axis, but this leads to a problem if an object is approaching another in a way that their corners would collide at a fast velocity, they will slip past each other and resolve on the wrong axis because one penetrated too deeply, for example:

We can see that the red square is approaching the green rectangle. They intersect and the solver sees that the smallest intersection is on the Y axis Pre collision and collision step

Thus they sepparate on the Y axis, and the red square flies by the green rectangle, when it should have stopped on the left edge

Post collision

I'm currently at a loss on how to solve this, any sugestions or fixes would be greatly appreciated!

\$\endgroup\$
  • \$\begingroup\$ You might want to look into continuous collision detection (CCD). It prevents problems such as these. Plus other problems caused by discrete solutions. \$\endgroup\$ – Andrew Wilson Dec 21 '16 at 22:54
1
\$\begingroup\$

I think you want to take the velocity direction into account when considering how to move the red box back. I'm thinking you want to move back along the velocity vector when you detect an intersection.

It seems you have the the x and y intersection depths, so just work out the magnitude of the 2D vector formed by those values and move the red box position by negative magnitude. Something like

inters_vec = (xintersect,yintersect)
velocity_dir = norm(velocity)
new_pos = red_pos - vel_dir*mag(inter_vec)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.