Size 16px character doesn't fit in a size 16px space

Godot Version

v4.6.3.stable.official [7d41c59c4]

Question

Hi everyone! Beginner here.

I have a 2d platformer. The character is a CharacterBody2d -node with a 16px * 16px recrangular CollisionShape2d. I move the character using “move_and_slide()”. The world is made out of a simple tilemap with only a single 16x16 yellow tile.

Since the player is only 16px tall and 16px wide, it should fit in a 1 tile hole, but it doesn’t. It acts as if there are no tunnels in the left wall and no holes to fall into.

If I place the player in one of the tight spaces in the editor and then start the game, the player is completely stuck.

I want the player to be able to move in all of the tight places pointed out in the image, without making the CollisionShape smaller; I don’t want the player to have any wiggle room in the tight spots. How do I achieve this?

Here’s 2 more images for additional information:

Thank you

I don’t know if this is the correct answer or will solve your problem; but this thread I remembered reading sounds like a similar problem

This might have to do with floating point boundaries/pixel coors.
If your character is on pixel.x = 0.4449 it won’t drop down into a well between pixel.x = 0 and pixel.x = 15 (with a 16px collision shape)
Also, check your CharacterBody2D safe_margin property and reduce that to 0 or near zero.

You can make the CollisionShape smaller (1-2 pixels from both sides). So it would slide in..

And for wiggling, you can create four more CollisionShape with different collision layer than the original one, they would be placed around the character. And you use them to check if the character is in between two walls. Then you can disable the axis moving accordingly.

Thank you for the replies. I believe I got the issue fixed.

I changed the CollisionShape2d size to 15.5px * 15.5px. Then, in the player_movement script, I added these two lines to the _physics_process function:

global_position.x = round(global_position.x)
global_position.y = round(global_position.y)

In practise, the player’s collisionShape seems to be exactly 16px. I mean the collisionShape doesn’t seem to ACT any smaller than 16, even though it is. These changes allowed the character to fit perfectly into 16px wide/tall tunnels. Still, the character sometimes dragged in a weird way while falling in a 16x16 sized hole. I UNCHECKED this box and everything started working perfectly: