How to deal with tiny collisions?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ThePixelGuy

Hello! The Player Node (KinematicBody2D) has an 8x8 CollisionShape2D, when I try to make it pass through an 8 pixels tall place, it won’t fit. When I drop the collision margin to 0.001 it sinks to the ground.
I want it to be able to pass through places exactly it’s height and not sink to the ground for obvious reasons. Thanks!

Cannot fit...

Here’s the code.

extends KinematicBody2D

 const GRAV = 0.5
 const ACCELERATION = 3.0

 var horizontal_speed = 0.0
 var vertical_speed = 0.0

 func _physics_process(delta):
var velocity = Vector2(horizontal_speed,vertical_speed)
var input_left = int(Input.is_action_pressed("ui_left"))
var input_right = int(Input.is_action_pressed("ui_right"))
var input_up = int(Input.is_action_pressed("ui_up"))
var input_down = int(Input.is_action_pressed("ui_down"))
var movement_dir = input_right - input_left
 #Horizontal Movement Processing
if abs(horizontal_speed) < 38:
	horizontal_speed += movement_dir * ACCELERATION
if abs(horizontal_speed) > 1:
	horizontal_speed -= horizontal_speed / 32
	horizontal_speed = 0
 #Vertical Movement Processing

move_and_collide(velocity * delta)
velocity = move_and_slide(velocity,Vector2(0,-1))
if is_on_floor():
	vertical_speed = 0
	vertical_speed += GRAV

I’m facing this problem too. Did you find any solution?

jlucasdelima | 2020-12-30 00:06

Sadly, without workarounds, this kind of pixel-perfect collisions are not possible. But the workaround in the tweet could work. Or you could shrink the CollisionShape2D in height, then have an Area2D that checks if the player is in a pixel-perfect gap, and the character is allowed to jump if only the Area2D is not detecting any collisions.

ThePixelGuy | 2020-12-30 06:55

:bust_in_silhouette: Reply From: Dooowy.

Interesting! You should try to make the CollisionShape2D’s height 7 instead of 8.

Thanks a lot! That is a very simple and easy solution and makes me feel silly to think that I couldn’t think of it! But, I kind of want to keep the CollisionShape2D 8 pixels tall… Is there any other way to get around?

ThePixelGuy | 2019-06-20 08:58

Plus, I would be able to jump in a place where my player shouldn’t be able to jump if I were to shrink CollisionShape2D, therefore, the sprite would go inside the tile.

ThePixelGuy | 2019-06-20 09:13