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've just successfully implemented Separating Axis Theorem (SAT) in my game but I was wondering how do I find the penetration vector? I heard it can be useful for collision response. e.g. The harder they collide the harder the response.

I want the penetration vector so I apply it to the position of an object when it is current penetrating an other so I can move it back outside of the other object's bounds.

Here is my code so far.

Any help would be much appreciated,

Thanks in advance.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The classic way to do this is the GJK algorithm. It's a fairly complicated algorithm with a lot of moving parts, so might be tricky to implement. However, there are many implementations out there on the Web that you might be able to adapt.

A simpler way to get an approximate penetration vector might be to leverage the SAT itself; when you iterate over all the possible separating axes and check for overlap on each, keep track of which axis has the shortest overlap and use that as the penetration vector.

share|improve this answer
    
Yeah I'm sure I could use what I already have to find it, So you said look at the overlaps and find the shortest one? Then what multiply the overlap by the axis? –  SyntheCypher Mar 14 '12 at 17:22
    
@SyntheCypher Exactly. The normalized axis multiplied with the shortest overlap will yield the penetration vector. –  bummzack Mar 14 '12 at 18:29
    
Ok well I tried that and I get a vector back but, it doesn't give me the exact x and y I need to move an object by to stop them from intersecting. :( –  SyntheCypher Mar 14 '12 at 22:34
    
@SyntheCypher The vector this produces should separate the two objects. It may not separate them in the best possible way, but if everything is working correctly the objects should definitely come out separated after one of them is translated by this vector. –  Nathan Reed Mar 14 '12 at 23:45
    
@Nathan Reed: Why do call it an "approximate penetration vector"? I was under the impression that this method always produces the optimal solution (just mathematically, not physically of course) –  TravisG Mar 15 '12 at 6:46

You should be already calculating it, atleast kind of. When projecting shapes onto a normal you're checking if two projections are overlapping. To make this information more usefull, you should store that value, that value is the distance the two shapes need to be moved in a given direction to avoid collision. Now to calculate the actual penetration vector all you have to do is check which value was the smallest and that's your penetration vector. That's all.

share|improve this answer
    
In addition, you should check out this link: codezealot.org/archives/55#sat-mtv –  TravisG Mar 15 '12 at 6:44
    
I have done but no one has explained how this method works "Collider.getDistance(m_min, other.m_max);" –  SyntheCypher Mar 29 '12 at 16:12

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.