Getting an OBB out of another OBB?
- by Milo
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.
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