Attention | Topic was automatically imported from the old Question2Answer platform. | |
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!
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)
#Inputs
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
else:
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
else:
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