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?
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.
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: