Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using this code to detect intersections between two OBBs. The problem is that i don't know what to do after detecting it. I tried using a simple algorithm:

    if (collision detected) {
        move character back to its position on previous frame
    }

But this is not what i need, because the character is rotating and moving to certain points (usually to mouse click position). When it's close to an object with OBB and it rotates to a point, its OBB updates (the position of all OBBs corners is recalculated) and most of the time the updated OBB intersects with an object that is near, so the charecter gets stuck at its position.

How can i deal with the rotation problem or what other methods can you offer for stoping character when its OBB itersects with another?

share|improve this question
1  
As soon as your moving objects rotate, it is a lot harder to use Axis-Oriented Bounding Boxes well. Also, in general it is better to check for collisions before movement(and prevent the movement from happening if there will be a collision), instead of trying to resolve overlap after movement. –  Qqwy Jan 29 '13 at 20:11
    
I have an idea, but i dont know how to implement it... What about finding the shortest way out of the obb? –  Chorche Jan 29 '13 at 20:18
1  
Maybe you can use the Euclidean distance and 2 radii of your 2 objects, so you can test spheres intersection instead of bounding boxes. Everything would be much easier. –  Ivan Kuckir Jan 29 '13 at 21:45
add comment

1 Answer

You need to find penetration distance and an axis of resolution. The axis of resolution will be the axis of least penetration between the two objects. Finding this information is non-trivial and makes for a much more in-depth implementation than the one you currently have.

See Box2D Lite for an example of an OBB to OBB test. For a working generalized polygon to polygon test, I suggest studying this: https://github.com/tutsplus/ImpulseEngine/blob/master/Collision.cpp

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.