Overlapping physics objects driving me mad :)

No, just that box2D has no way to simulate impossible situation like two physics bodies occupying the exact same space, so the results are unpredictable.

How about an “explosion” (using linearImpulse from the world point of where the new body will appear, acting on all the currently existing bodies), to displace all the other bodies a few frames before the new body appears in the hole opened up. In my experience, getting the force of the linearImpulse right could be tricky, as it would depend on the total mass of bodies pressing down on the spot you’re trying to open up. If there’s a lot of mass, the bodies won’t move at all, whereas if the combined pressure is low the bodies could go flying (perhaps have a counter tracking the total mass of all bodies as they are created, and use that to gauge the strength of explosion needed)

Hi @yojimbo2000 , indeed, linearImpulse is tricky to use in my case.

But this made me think of something: is there a quick and easy way to know, one frame before building it, if my newly-made body will be set on top of another?

If so, I could just adjust the coordinates I will set the new bodies at, with something like createNewBody(touch.x,touch.y+math.random(-10,10)).

I guess first create a dummy body set to sensor (so it doesn’t disturb the physics), then do a check for overlaps.

Bullet set to true in my test didn’t work either. Bullet is for fast moving objects to prevent tunneling, not for overlapping objects. When some of my objects overlap, they start to spin slowly because they’re trying to seperate from each other and also reacting to the objects around them. Also, the objects don’t have to overlap exactly. If one of them is created over the arm of another, they still stay overlapped. I think that all the points are reacting to each other and depending on their position, just get pushed back and forth and can’t get away.

Though it may be difficult, i had the idea of making the object grow a different way; make it completely flat then expand it along just one axis to its full size. This way it doesnt slide the objects horizontally, just pushes them up. And even easier, use the physics “edge” type for the bottom so te flat object doesnt clip

Alright, after trying many other, simpler, solutions, I’m now convinced I need to try something along the line of @Monkeyman32123 solution.

I’m thinking of resizing the bodies from tiny to normal size in, say, 5 to 10 frames. Is there a mathematic way to reconstruct a physics body, or its corresponding vector shape:

points = {vec2(x1,y1),vec2(x2,y2),vec2(x3,y3),vec2(x4,y4),vec2(x5,y5),vec2(x6,y6)}

according to a scale factor? (am I even making sense?)

Something like this?

local points = myBody.points
local scale = 0.1
for i,v in ipairs(points) do
    v = v * scale
end
-- myBody.points = points --don't think this works,
-- so I guess you have to destroy and reinitialise the body? 
myBody:destroy()
myBody=physics.body(POLYGON, unpack(points))