From 29af8d20a51b740cd8e96ba08692ddbb354efef3 Mon Sep 17 00:00:00 2001 From: Cass Unterholzner Date: Sun, 21 Sep 2025 11:22:52 -0500 Subject: [PATCH] Added rotating character during movement --- characters/character.gd | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/characters/character.gd b/characters/character.gd index d78e487..e8f6f0f 100644 --- a/characters/character.gd +++ b/characters/character.gd @@ -4,17 +4,24 @@ var is_selected: bool = true @export var speed: float = 5.0 var target_position: Vector3 = Vector3.ZERO var has_target: bool = false +var target_rotation: float = 0.0 +@export var rotation_speed: float = 0.2 func _physics_process(delta: float) -> void: if has_target: var direction = (target_position - global_transform.origin) direction.y = 0 - if direction.length() < 0.1: - velocity = Vector3.ZERO - has_target = false + if is_equal_approx(global_rotation.y, target_rotation): + if direction.length() < 0.3: + velocity = Vector3.ZERO + target_rotation = global_rotation.y + has_target = false + else: + direction = direction.normalized() + target_rotation = atan2(direction.x, direction.z) + velocity = direction * speed else: - direction = direction.normalized() - velocity = direction * speed + global_rotate(Vector3.UP, (target_rotation - global_rotation.y) * rotation_speed) move_and_slide() -- 2.51.2