From 8fc0ed92188a6503de8c83059c39ab1accbd5292 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 12 Feb 2024 08:16:59 -0600 Subject: [PATCH] cleaned up player movement code --- scripts/player.gd | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/player.gd b/scripts/player.gd index ca3149c..0a70a3e 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -11,17 +11,10 @@ var color := Color.WHITE var lives: int = 1 func _physics_process(delta: float) -> void: - velocity = Vector2.ZERO - if Input.is_action_pressed("ui_down"): - velocity += Vector2.DOWN - if Input.is_action_pressed("ui_up"): - velocity += Vector2.UP - if Input.is_action_pressed("ui_left"): - velocity += Vector2.LEFT - if Input.is_action_pressed("ui_right"): - velocity += Vector2.RIGHT - velocity = velocity.normalized() * speed + var input_direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") + velocity = input_direction * speed move_and_slide() + for i in range(get_slide_collision_count()): var collision := get_slide_collision(i) if collision.get_collider() is Chest: