3
\$\begingroup\$

I have many objects with AABBs and a player surrounded in an AABB. If I represent my player with a point everything works smooth with detection and wall sliding as a response (for example what wall sliding is, see this video).

If I represent my player with an AABB I first check if there is any AABB - AABB collision which works fine but I want the same sliding effect with this AABB box. I worked out a little trick to find the normals of both faces that collide but only works when I'm moving in one axis so that shouldn't be how it's done.

Below you'll see my scene. You'll see cubes surrounded with an AABB with a small offset and my camera that is at the center of an AABB (red lines).

a scene with three cubes

How does one provide a good seamless AABB - AABB collision response algorithm that is not too hard to implement (like the one in the youtube video). I couldn't find anything useful on the web.

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

You say you have found the collision normal. Since the shapes are AABBs, the normal will always be along one axis (six directions). All you need to do, then, is modify the player state as follows:

  1. set the velocity component along that axis to zero.
  2. set the position component along that axis to the “just exactly touching” distance, which is easy to calculate from the dimensions of the AABBs.

Further details:

  • Make sure that you do this with respect to the box the player collides with first (which you can determine by dividing the penetration depth by the velocity), otherwise you might penetrate it by adjusting the position for the second.
  • Adjusting the position might cause yet more different collisions. Check for those and respond to them too. If you have many close surfaces (narrow corridors made out of boxes) then it's hairy to ensure you can never have a conflict, and you might have to switch to 'soft' collisions, but for mostly wide separated boxes like in your screenshot this is sufficient.

This is just the special case of collision response for axis-aligned surfaces; non-axis-aligned surfaces would need dot products and projections with the surface normal, but here they all simplify to modifying a single axis. It's a special case of the same thing.

\$\endgroup\$
7
  • \$\begingroup\$ Thanks, I think I can manage that. I have one other question. If I want to restore my player's position after a collision occurs to just outisde the colliding cube. I am not sure how to calculate that exactly since it depends on my angle how deep I'm entering the cube? Is this simply a matter of adding the inverse normal of the colliding cube times the velocity vector to my position? newpos = pos + (invNormal * velocity) ? \$\endgroup\$
    – Joey
    Feb 28, 2013 at 18:15
  • \$\begingroup\$ I coded your suggestions and the sliding goes smoothly right now so that works but I came upon another problem. My calculations for the normal vector of the colliding plane was just an approximation and that approximation fails when I'm moving along two axes instead of 1, giving me weird results. I'm not sure how to get the plane normals in an accurate way. \$\endgroup\$
    – Joey
    Feb 28, 2013 at 19:14
  • \$\begingroup\$ @Joey Here's that question already asked and answered. \$\endgroup\$
    – Kevin Reid
    Mar 1, 2013 at 22:31
  • \$\begingroup\$ Thank you Kevin. I'll look into that and figure out how to calculate the normals properly! Thanks for your help :) \$\endgroup\$
    – Joey
    Mar 2, 2013 at 11:14
  • \$\begingroup\$ One small question though. I need to be able to do Plane - AABB collision to perform that check. Is this simply a matter of comparing distances along the normal axis (via plane equation) of each plane? \$\endgroup\$
    – Joey
    Mar 2, 2013 at 11:19
2
\$\begingroup\$

What you are referring to is known as a collide and slide algorithm. This is frequently used for player controllers, and cameras. The following links may be able to help you.

http://www.peroxide.dk/papers/collision/collision.pdf http://www.gamedev.net/topic/556184-character-controller/

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks for the reply! I've seen the article before and read it globally once but it's mainly about ellipse collision detection and isn't working with AABB. It's also a bit too complex for my needs. \$\endgroup\$
    – Joey
    Feb 28, 2013 at 15:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .