From 1c70488ea5649186f528e777e0d835e5d3b0f190 Mon Sep 17 00:00:00 2001 From: Nikolai Fedorov Date: Thu, 23 Apr 2026 18:53:40 +0300 Subject: [PATCH] add animation on movement --- scripts/Player.gd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/Player.gd b/scripts/Player.gd index 6d93b2d..84ec083 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -118,8 +118,16 @@ func _handle_movement(delta: float) -> void: float(Input.is_key_pressed(KEY_S) or Input.is_key_pressed(KEY_DOWN)) - float(Input.is_key_pressed(KEY_W) or Input.is_key_pressed(KEY_UP)) ) + var is_moving: bool = abs(input_x) > 0.0 or abs(input_z) > 0.0 + if is_moving: + if not anim_player.is_playing() or anim_player.current_animation != "walk": + anim_player.play("walk") + else: + if anim_player.current_animation == "walk": + anim_player.stop() + var cam := get_viewport().get_camera_3d() - if (abs(input_x) > 0.0 or abs(input_z) > 0.0) and cam != null: + if is_moving and cam != null: var cam_fwd := -cam.global_transform.basis.z cam_fwd.y = 0.0 cam_fwd = cam_fwd.normalized() if cam_fwd.length() > 0.01 else Vector3(0.0, 0.0, -1.0)