AABB Multiple Collision Response
Posted: Sun Jun 13, 2010 4:25 pm
I'm trying to figure out how to deal with collisions between multiple objects. I'm using Falco's AABB collision function which returns both a boolean value and the normal of intersection.
Right now I have three different types of objects: Player (Any character), Dynamic (pushable), and Solid (does not move)
The following response causes the second object to be pushed by the first (player kicks a can out of his way)
This response causes the first object to be stopped by the second (player walks into a wall)
The problem is handing collisions between the different types of objects.
This is what I'm playing with at the moment:
The major mishap occurs when the player is pushing a dynamic object that then collides with solid object. This forces the player through the dynamic object (see illustration below)
The first way I tried to solve this was to set the dynamic object's type to solid while it was colliding with a solid, but I couldn't figure out how or when to change it back to dynamic (so it would become "stuck" as if it were a solid itself).
How would you handle collisions between objects with different properties?
Thanks for reading!
Right now I have three different types of objects: Player (Any character), Dynamic (pushable), and Solid (does not move)
The following response causes the second object to be pushed by the first (player kicks a can out of his way)
Code: Select all
objects[j]->Center( objects[j]->Center() + normal );
Code: Select all
objects[i]->Center( objects[i]->Center() - normal );
This is what I'm playing with at the moment:
Code: Select all
for( int i = 0; i < numberOfObjects; i++ ){
    for( int j = 0; j < numberOfObjects; j++ ){
        if( AABBCollisionCheck(objects[i], object[j], normal) ){
            //PLAYER pushes DYNAMIC
            if( objects[i]->Type() == PLAYER_OBJECT && objects[j]->Type() == DYNAMIC_OBJECT ){
                objects[j]->Center( objects[j]->Center() + normal );
            //PLAYER is stopped by SOLID
            }else if(objects[i]->Type() == PLAYER_OBJECT && objects[j]->Type() == SOLID_OBJECT ){
                objects[i]->Center( objects[i]->Center() - normal );
            //DYNAMIC is pushed by PLAYER
            }else if( objects[i]->Type() == DYNAMIC_OBJECT && objects[j]->Type() == PLAYER_OBJECT ){
                objects[i]->Center( objects[i]->Center() - normal );
            //SOLID is unaffected by PLAYER
            }else if( objects[i]->Type() == SOLID_OBJECT && objects[j]->Type() == PLAYER_OBJECT ){
                objects[j]->Center( objects[j]->Center() + normal );
            }else{
                objects[i]->Center( objects[i]->Center() - normal );
                objects[j]->Center( objects[j]->Center() + normal );
            }
        }
    }
}
Â
The first way I tried to solve this was to set the dynamic object's type to solid while it was colliding with a solid, but I couldn't figure out how or when to change it back to dynamic (so it would become "stuck" as if it were a solid itself).
How would you handle collisions between objects with different properties?
Thanks for reading!