1
\$\begingroup\$

I am working on a simple rigid-body physics engine ,I've already implemented SAT algorithm for collision detection and everything works fine, Now i get to step to use MTV to calculate the distance which objects might move to, In my case the two objects are cubes ,Actually i am a little confused about the distance and how to use it

Here is the two cubes

Huge Cube and Small One

Both of them are on the same y-axis and z-axis, Only differs in x-axis

I am calculating MTV and i get:

samllest which refers to the smallest axis, So it looks like (x,y,z).

overlapDistance which refers to the smallest overlap distance as a double variable.

I know that overlapDistance is the distance that one of two cubes should move till no collision

But how to use it , How cubes should respond to this distance ?

Sorry if i am not clear, but for summary i know the smallest overlap distance but i don't know how to get use of it

\$\endgroup\$
  • 1
    \$\begingroup\$ What is the context? Do you want to separate the two cubes if they overlap, or do you want to resolve a collision? The MTV is fine in the first case, but pretty much useless in the latter \$\endgroup\$ – Bálint Jun 2 at 16:09
  • \$\begingroup\$ I want to resolve the collision so each cube goes to the right place , Any idea for this i would be thankful \$\endgroup\$ – Abdulrahman Jun 2 at 17:26
3
\$\begingroup\$

The minimum translation vector isn't a good choice when resolving collision. For example, let's look at the following case:

enter image description here

The three parts of the image show the three states of the physics engine given a static square and a dynamic one (for simplicity). The dynamic object enters the static one during the update. The minimal translation vector is always the shortest vector, that completely separates the two objects, but it's not always the correct one. The MTV here dictates, that the shortest path to separation is to move the dynamic object vertically upwards. This shouldn't happen, since it entered the static one from the sides and everyone would expect it to stop. This leads to the dynamic object essentially jumping across the static one.

If you want to separate the squares realistically, follow this answer

If you don't care, then it's pretty simple. Just take the smallest vector, multiply it by overlapDistance and subtract it from the position of the moving square

\$\endgroup\$
  • \$\begingroup\$ So clear and helpful , Many thanks \$\endgroup\$ – Abdulrahman Jun 2 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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