Hi everyone,
I've been following the following tutorial to teach myself a bit of Godot (3.5), https://www.codingkaiju.com/tutorials/beginner-godot-2d-platformer/#Create_the_Player But I've been having a problem where my player sprite sometimes hovers a single pixel above the ground. The player is a KinematicBody2D, the terrain is a TileMap.
Screenshots as example:
My movement code is the following:
extends KinematicBody2D
export var move_speed := 100
export var gravity := 2000
export var jump_speed := 550
var velocity := Vector2.ZERO
func _process(_delta):
change_animation()
func change_animation():
if velocity.x > 0:
$AnimatedSprite.flip_h = false
elif velocity.x < 0:
$AnimatedSprite.flip_h = true
if velocity.y < 0:
$AnimatedSprite.play("jump")
else:
if velocity.x != 0:
$AnimatedSprite.play("walk")
else:
$AnimatedSprite.play("idle")
func _physics_process(delta):
velocity.x = 0
if Input.is_action_pressed("move_right"):
velocity.x += move_speed
if Input.is_action_pressed("move_left"):
velocity.x -= move_speed
velocity.y += gravity * delta
if Input.is_action_pressed("jump"):
if is_on_floor():
velocity.y = -jump_speed
velocity = move_and_slide(velocity, Vector2.UP)
I've tried decreasing the pixel margin the physics simulation uses, turning off pixel perfect rendering, etc... but none of them seem to work. It doesn't seem to be related to the animation either since removing all of them has the issue subsist. The collision shape is a simple rectangle as well.
If I turn on collision shapes it seems to always happen when standing on or near the boundary between two tiles.