Rigidbody falls into tilemap cell by a fraction of a pixel

Godot Version

Windows 4.2.1


This is happening in a project I’m working on, and I was able to pretty easily recreate the issue in a simpler project. The y position of a rigidbody is not quite behaving as I expect. The rigidbody starts above the tiles and falls onto them. I expect the ending position of the rigidbody to be a round number, but instead it’s a fraction of a pixel off, which would put the bottom of the body slightly inside of the tile cell. The tilemap position is sitting at a round pixel number, there’s no offsets or anything like that, and the collision mask of that particular tile is set to the full cell.

Is this normal? Is there anything I can do to avoid this?

Here’s a screenshot of the recreation: Imgur: The magic of the Internet

Edit: Adding that this is not specific to Tilemap physics. I tried placing the rigidbody over a staticbody node and the same thing happened. I did notice that the object is getting some random small changes in linear_velocity.y even though it should be at rest. During these moments, the position jumps between the correct y value and the slightly-off y value. (edit: realized the source of this behavior was a bandaid fix i was attempting to fix the y value with, so disregard)

Have you tried blocking the way with an extra Collisionshape2D? Adding extra collisions that aren’t connected to any visible object can be a fun easy way to not only add secrets and eastereggs but also patch most any hole the player is finding during testing.

Thanks for the suggestion. I really just want to know why this is happening.

After some further testing, I’ve noticed that the rigidbody actually gets a miniscule linear_velocity.y amount randomly every few seconds when it should actually be at rest on the floor. Godot seems to be having trouble actually letting the object rest at the correct y value.

You may need to adjust your physics margins so they are more suited to the size of your simulation. The default physics in Godot are tuned for speed with many objects, rather than accuracy with few. You should also make sure you’re not modifying physics-controlled values outside the physics thread (aka _physics_process()) or you will see calculations happen out of sync. There are other possible reasons for this issue, but you’d need to provide more details on how you set everything up.

Hey Efi, thanks for the answer. As far as Physics settings go, I’m on all default values for this test.

Here are my steps to recreate in the simplest and quickest way:

open a new scene with a 2dNode root and add a rigidbody2D and staticbody2D. I used the Godot icon, which is 128x128 and set the collisionshapes of the bodies to match that size. Place the rigidbody anywhere above the staticbody and run the project so the rigidbody falls onto the staticbody. Open the remote inspector and click on the Rigidbody node. The y value of the rigidbody’s position will be some decimal pixel value instead of a round number. In testing just now, mine was 247.104 when I expected it to just be 247.0.

The fact that it happens easily in a blank project gives me faith that I didn’t do something wrong in my active project.

If there’s a setting to tweak to prevent this, I’d prefer that, but if not then that’s fine too. Ultimately, I can work around this, but I’m very new with Godot so I wanted to confirm that this was expected behavior.

This is fine for the defult physics. As I said, it is meant for many things moving and bouncing, not for precise/stable physics. Those are more costly. If you want objects to stay at the floor, the usual way is to get the collision position, snap to it and then freeze the object until another collision happens. That’s how most games do it. If you want precission physics that’s an entirely different problem.

1 Like

Thank you! Really appreciate the insight and assistance.