extends Node const AIM_TEXTURE := preload("res://assets/icons/ui/aim_cursor.svg") const HOTSPOT := Vector2(24, 24) var player: CharacterBody2D var aiming := false func _ready() -> void: process_mode = Node.PROCESS_MODE_ALWAYS func should_aim() -> bool: return is_instance_valid(player) and not bool(player.get("_is_destroyed")) and not bool(player.get("is_docked")) and not get_tree().paused and not get_viewport().gui_is_dragging() and get_viewport().gui_get_hovered_control() == null func _process(_delta: float) -> void: var next := should_aim() if next == aiming: return aiming = next # A hardware cursor keeps the hotspot exactly on the weapon aim point. Input.set_custom_mouse_cursor(AIM_TEXTURE if aiming else null, Input.CURSOR_ARROW, HOTSPOT if aiming else Vector2.ZERO) func _exit_tree() -> void: if aiming: Input.set_custom_mouse_cursor(null, Input.CURSOR_ARROW)