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 was following codezealot's tutorial on SAT and MTV and trying to implement it myself but I've come a cropper when it comes to getting the correct MTV. Here is my example: (Cue pretty pictures...)

enter image description here

I'm well aware how to obtain the length of the MTV and the axis on which it lies. However I can't work out whether the length should be 'positive' or 'negative' to push the object in the correct direction.

In the example we are separating the objects by moving the 'red' of the 'blue', the top example is moving the object negatively and the bottom moving it positively.

Please help I'm really struggling with this.

Here is my actual implementation.

share|improve this question
I was looking for similar questions. They're all by you. Been a tricky problem eh? –  Byte56 Apr 17 '12 at 23:43
add comment

3 Answers

up vote 2 down vote accepted

Well I worked out a way but I'm not sure if it's the best way:

What I did was once I'd found the smallest overlap is check if x1 < x2 if so the length must be positive else the length must be negative.

It's worked so far and given me satisfactory results.

share|improve this answer
This is what I found myself having to do: I compared the positions of the two bodies along the axes checked to see if A's position was in the positive or negative direction from B along that axis, and adjust the sign of the displacement accordingly. –  Jonathan Hobbs Apr 18 '12 at 21:52
add comment

The solution is to simply turn around the displacement vector (multiply it by -1) if it's pointing towards the shape from which the object needs to be pushed away.

To find out if the displacement vector is pointing towards the shape, you first have to get the general direction from object a to object b by subtracting their centers from each other. After that, you check the dot product between the displacement vector and the direction(a,b) vector that you just created. If it's > 0, the displacement vector and direction(a,b) are pointing in the same direction, hence you need to flip the displacement vector.

share|improve this answer
add comment

From what is understood, this overlap value should always be positive. The actual direction of the force should be derived from the projection vector (the MTV axis).

Note the interactive example on the page referenced by codezealot (figure 5): http://www.metanetsoftware.com/technique/tutorialA.html

It seems like the actual direction is the MTV axis pointed by where the centers of the objects meet along the axis. Figure 5 of that tutorial is the best illustrator of this. Move the object around and watch the centers of the objects vs an invisible line drawn parallel with the axis from the center of both objects. The direction of the vectors change when the centers cross that line.

share|improve this answer
Is MVT different from MTV? –  SyntheCypher Apr 18 '12 at 12:37
No, just the order of the letters. Editing. –  Alex Shepard Apr 19 '12 at 0:24
add comment

Your Answer


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.