From 50bbd78463974183f96e71abb269a30f9ad9e423 Mon Sep 17 00:00:00 2001 From: Nikolai Fedorov Date: Wed, 22 Apr 2026 17:05:16 +0300 Subject: [PATCH] rmb for aiming --- scripts/Main.gd | 2 ++ scripts/Player.gd | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/Main.gd b/scripts/Main.gd index b371140..0c0d5cc 100644 --- a/scripts/Main.gd +++ b/scripts/Main.gd @@ -184,6 +184,8 @@ func _process(delta: float) -> void: var look_at_pos := player.global_position + Vector3(0, 0.8, 0) camera.global_position = camera.global_position.lerp(look_at_pos + offset, 14.0 * delta) camera.look_at(look_at_pos, Vector3.UP) + if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT): + player.set_aim_direction(deg_to_rad(cam_yaw)) # ─── Player ─────────────────────────────────────────────────────────────────── diff --git a/scripts/Player.gd b/scripts/Player.gd index c4e2ab4..5a06d92 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -16,6 +16,9 @@ var invincible_timer: float = 0.0 var is_alive: bool = true var last_move_dir: Vector3 = Vector3.FORWARD +var _aim_yaw: float = 0.0 +var _is_aiming: bool = false + @onready var mesh_node: MeshInstance3D = $BodyMesh @onready var indicator_node: MeshInstance3D = $KickIndicator @@ -96,11 +99,15 @@ func _handle_movement(delta: float) -> void: velocity.x = move.x * move_speed velocity.z = move.z * move_speed last_move_dir = move - var target_y: float = atan2(-move.x, -move.z) - rotation.y = lerp_angle(rotation.y, target_y, 16.0 * delta) + if not _is_aiming: + var target_y: float = atan2(-move.x, -move.z) + rotation.y = lerp_angle(rotation.y, target_y, 16.0 * delta) else: velocity.x = move_toward(velocity.x, 0.0, move_speed * 12.0 * delta) velocity.z = move_toward(velocity.z, 0.0, move_speed * 12.0 * delta) + if _is_aiming: + rotation.y = lerp_angle(rotation.y, _aim_yaw, 14.0 * delta) + _is_aiming = false velocity.y = 0.0 move_and_slide() @@ -142,6 +149,10 @@ func _do_kick() -> void: if kicked_any: _squish_effect() +func set_aim_direction(yaw_rad: float) -> void: + _aim_yaw = yaw_rad + _is_aiming = true + func _squish_effect() -> void: var tw := create_tween() tw.tween_property(mesh_node, "scale", Vector3(1.3, 0.55, 1.3), 0.07)