Looking for assistance in getting visually accurate blocks stacking

Godot Version

Windows 11, Godot 4.2.1


Hello, I’m noticing a gap when stacking RigidBody2D blocks vertically. See the small gap above the topmost block in the screenshot below. If stacked correctly, the top of the topmost block should be even with the ceiling above it. Instead, there’s a gap of a few pixels or so.

The reason for the small gap is because the blocks are sinking into each other by a fraction of a pixel. I recently posted about that here and ultimately accepted it as a slight limitation of the physics engine.

So I’m wondering now - what would be a solution to keeping these RigidBody2Ds at their correct vertical position? Every workaround I’ve tried for this screen in particular has had unintended results like jittering or floating.

Thanks for any insight here.

You could have the physics frozen on them until they are disturbed. That way they’ll stay aligned until one is modified at least.

Hey Efi! That was one of the workarounds I tried with mixed success. Starting with freeze = true has the stack displayed correctly, but I’d still like gravity to affect the tower when the bottom piece is removed.

I tried starting the blocks with freeze = true and using a shapecast to detect if there’s empty space underneath to trigger freeze = false until it hit something but that resulted in jittering and unpredictable gaps between blocks.

Now I’m kinda wondering if it would make sense to temporarily “combine” stacked blocks into a single entity?

You could make it so the moment any of them moves they signal the entire stack to start moving. Sadly, the way the default physics works in godot means rigid bodys can’t really stack like that. You could try increase the solver accuracy and speed to diminish the jittering if there are not many live objects at once. By default godot it tuned to handle hundreds iirc.

Hey Efi, appreciate the response again. I actually didn’t realize there were more physics settings hidden under the “advanced” toggle so thanks for leading me in that direction haha. They help a little, and it’s good to know those options are there. For the longest time I was absolutely at the end of my wits trying to figure out why (most of the time) the blocks would sink into each other by exactly .3 pixels, and now I see that .3 pixel overlap is the default value for defining a “collision” in the advanced physics options. So at least that’s one mystery solved.

I think once I’m deeper into the game I’ll come back and try some more ideas to make this stack behave better but for now, this is the only screen where the stack is nearly that high so I’ll just reluctantly move on.