Overlapping of bodies

Hello..
i am facing a problem in box2d..i am creating many bodies one on each other i.e making stacks of bodies..but they are overlapping each other..that doesnot make sense..as physics solid body cannot overlap each other..kindly help
This can happen if heavy objects are stacked on top of light objects. Is this the type of situation you have? You can increase the number of iterations the world step does to make the simulation correct quicker.
Thanx for your reply
There are approximately 15-20 dynamic bodies in a world....if i increase the iterations then it makes the game slow and bodies move very slowly..

int32 velocityIterations = 8;
int32 positionIterations = 1;
uint substeps = 1;
float32 subdt = (1.0f/60.0f) / substeps;

for (uint i = 0; i < substeps; i++) {
if (world!=nil) {
world->Step(subdt,velocityIterations,positionIterations);
}

}
increasing the substeps makes my game slow...Kindly suggest the relevant solution..
When I said 'iterations' I didn't mean you need to do the step many times yourself, I was talking about the values for velocityIterations and positionIterations 😉

Could you show a screenshot or something... Box2D is not able to perfectly prevent all overlapping, it may be that the case you have is a difficult one.
I have tried all possible values of velocity and position iterations too...no doubt this removes overlapping at a certain level..but this makes my game too slow and bodies move very slowly..could you please try it by yourself??..make two stacks of bodies and move them through user touch..when they fall on each other..they overlap... 🙁
15-20 bodies is no problem for iPhone, it should be accurate without needing to be slow, and the typical values for vel/pos iterations (8/3) should be fine. Could you show a screenshot of the overlapping? With the app running on the device you can take screenshots with Xcode's organizer.

Are you using debug draw to show the shapes? Are they overlapping only when you 'move them through user touch', or all the time? How many vel/pos iterations does it take to get an accurate result?
I'm guessing there are three possibilities here:
- you are expecting a better result than Box2D can give for objects with very different masses
- your drawing code is incorrect
- your 'moving through touch' code is setting the position directly (ie. teleporting the body into others)

Original thread: https://box2d.org/forum/viewtopic.php?t=8086