Godot Version
<ver4.2>
Question
<my player somehow floating one pixel above the ground. Do you have any idea why?
<ver4.2>
<my player somehow floating one pixel above the ground. Do you have any idea why?
without much information to go with, I wouldn’t know the exact reason.
For the start, I’d check:
I dont think there are any problems on the tileset. and collision is properly aliened to player sprite.
I found out that not only player is floating 1px above the ground but enemies as well
I would run the game and then inspect the Remote tab, specifically in concern to the player position and the tileset position. Checking if there are any offset. If there aren’t, manually set the player position’s y value so they touch the floor and see what the physics do (does it accept the player or is the player pushed back up by one pixel again?)
just went and check remote tab, and player node2d position was kinda weird. is this maybe the reason?
What code are you using to apply gravity? It could be stopping short of pulling the objects all the way to the ground, if there’s less than 1 unit between them.
Additionally, the scaling on that ground texture seems a bit off. Some pixels are larger than others. The same sub-pixel differences causing that might be distorting the space between the objects and ground too, making it look like there’s a space when there really isn’t.
I’d suggest upgrading to Godot 4.3. It improved support for pixel-perfect graphics considerably.
thanks for the reply!
I dont think this is caused by the gravity. (I simply use “velocity.y += gravity * delta”)
Id refuse to upgrade to 4.3 for while, since im using various plugins. seriously, this is very frustrating, since this want an issue while ago. I just realised every node with collisionshape2d is floating above the ground recently.
If you’re using Snap 2D transforms to pixel
, previously Godot used floor()
to snap pixels. What that means is, with collision, pushing even 0.00001 pixel in another direction will have it snap, hence the 1 pixel gap. 4.3 fixed that by using a form of rounding instead.
oh i see… so what is the solution rather than upgrading to 4.3. disable snap 2d ?
If you don’t want to upgrade for the fix, I guess there’s some manual stuff you could do. For example, anything with collisions you could attach a script that rounds your position, or holds the actual position of the object as a separate variable, use that for physics calculations, and round the result every frame.