I'm writing a simple physics system for fun, and I've run into a problem that has me stuck.
The basic algorithm now is:
- Move an object
- Check for collisions
- If there was a collision
- Move the object the minimum distance to resolve the collision.
- Adjust the velocity based on the normals, masses, etc
I have one moving body moving toward two, static, massless, bodies.
The moving object is translated in one step to collide with one of the bodies.
I respond by finding the smallest distance I can move so that they are no longer colliding. In this case, that means moving the dynamic body straight down. However, now it is colliding with another box.
I repeat the same thing with that box, trying to move the dynamic box so that it is no longer colliding, but that pushes it back into the first box. This repeats forever. Is my algorithm fundamentally flawed?
min_o
can be a really small value,1/min_o
is potentially really big. Also if you look at units it seems wrong: bothv
andmin_o
are distances, so-v / min_o
is dimensionless, you cannot assign that to a distance vectorv2
. I don't totally understand how you definemin_o
, but you probably should just add or subtract something, or like in my answer, just go back to the previous position and redo the minimum possible step. – Skyrocket