5
\$\begingroup\$

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

Sample image of objects in room

I know how to check for collisions between the objects with an AABB-AABB intersection.

How do I calculate an appropriate collision response to make them frictionlessly slide against each other as they collide?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Are you talking about objects sliding on top of other objects here? What do you mean by "'sliding' / response"? \$\endgroup\$ Mar 21, 2012 at 18:00
  • \$\begingroup\$ 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 \$\endgroup\$
    – PeeS
    Mar 21, 2012 at 18:23

1 Answer 1

7
\$\begingroup\$

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 :)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I find it useful to think of this as the vector rejection (actual name) of the player's velocity on the normal - vector rejection takes the player's velocity, and subtracts the part that is parallel to the normal, leaving only the component perpendicular to the normal (sliding along the object). \$\endgroup\$
    – user253751
    Dec 30, 2014 at 1:48

You must log in to answer this question.

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