Getting an OBB out of another OBB?

Posted by Milo on Game Development See other posts from Game Development or by Milo
Published on 2012-11-10T01:05:08Z Indexed on 2012/11/10 5:16 UTC
Read the original article Hit count: 329

Filed under:
|

I'm working on collision resolution for my game.

I just need a good way to get an object out of another object if it gets stuck. In this case a car.

Here is a typical scenario. enter image description here

The red car is in the green object. How do I correctly get it out so the car can slide along the edge of the object as it should.

I tried:

if(buildings.size() > 0)
    {
        Entity e = buildings.get(0);
        Vector2D vel = new Vector2D();
        vel.x = vehicle.getVelocity().x;
        vel.y = vehicle.getVelocity().y;
        vel.normalize();
        while(vehicle.getRect().overlaps(e.getRect()))
        {
            vehicle.setCenter(vehicle.getCenterX() - vel.x * 0.1f, vehicle.getCenterY() - vel.y * 0.1f);
        }
        colided = true;
    }

But that does not work too well.

Is there some sort of vector I could calculate to use as the vector to move the car away from the object? Thanks

© Game Development or respective owner

Related posts about java

Related posts about collision-resolution