# AABB - AABB Collision response (sliding)

Here is the situation:

• I have a room with objects inside
• Each object has it's own AABB

Here is what I do:

• I check for collision between objects by checking AABB-AABB intersections

Here is what I need:

• How do I calculate the 'sliding' / response between those AABBs?
-
Are you talking about objects sliding on top of other objects here? What do you mean by "'sliding' / response"? –  XiaoChuan Yu Mar 21 '12 at 18:00
XiaoChuan Yu - i want my Player object when in collision with other to get a response from Collision between two AABBs - so that when player gets into collision with sphere when walking - he slides on the sphere AABB face it collided with –  PeeS Mar 21 '12 at 18:23

What you're looking to do is have the solid object (wall, obstacle, etc.) push back with a force equal to that which the player is exerting on it. In a simulated physical world, applying forces will not result in the behavior you want, so the velocity of the player has to be changed directly. This is what's known as an impulse.

The impulse you want to apply to the player's velocity vector is:

``````impulse = -(player.velocity * collision.normal) * collision.normal
``````

Where `collision.normal` is the normal of the face of the AABB that the player is colliding with. This is simply projecting the player's velocity vector onto the face's normal, obtaining the velocity change that the AABB will enact on the player (it is negated because technically we would subtract this vector from the player's velocity, but conceptually it makes more sense to add it). Finally, add the impulse to the player's velocity:

``````player.velocity += impulse
``````

And the result will be the component of the players velocity which was horizontal to the obstacle, so the player will 'slide' along the object. Note that this will work even if the player is sliding directly along the sphere, provided you calculate the collision normal correctly.

Hope this helps :)

-
ktodisco, great answer ! Thanks. –  PeeS Mar 22 '12 at 8:43