extends Node2D var anchor := Vector2.ZERO var anchor_mode := false var drag_distance := Vector2.ZERO var max_length := 75.0 var arrow_scene = preload("res://Player/arrow.tscn") var arrow: Node2D var process_touch := false func _ready() -> void: if OS.has_feature("mobile"): scale = Vector2(2, 2) $DrawLine.visible = false $TargetLine.visible = false func _input(event: InputEvent) -> void: if event is InputEventScreenTouch: if event.is_pressed(): process_touch = true elif event.is_released(): process_touch = false func _process(_delta: float) -> void: if Input.is_action_just_pressed("click"): global_position = get_global_mouse_position() anchor = get_global_mouse_position() anchor_mode = true arrow = arrow_scene.instantiate() arrow.global_position = global_position get_tree().current_scene.add_child(arrow) $DrawLine.visible = true $TargetLine.visible = true $TargetLine.origin = anchor $TargetLine.queue_redraw() elif Input.is_action_just_released("click"): anchor_mode = false arrow.velocity = -drag_distance * 1.5 arrow.flying = true arrow = null $DrawLine.visible = false $DrawLine.clear_points() $TargetLine.visible = false $TargetLine.queue_redraw() elif Input.is_action_pressed("click"): drag_distance = get_global_mouse_position() - anchor rotation = atan2(drag_distance.y, drag_distance.x) var max_distance = get_global_mouse_position() if drag_distance.length() > max_length: drag_distance = (max_length / drag_distance.length()) * drag_distance max_distance = anchor + drag_distance $DrawLine.clear_points() $DrawLine.add_point(Vector2.ZERO) $DrawLine.add_point((max_distance - global_position) / scale) $DrawLine.rotation = -rotation $TargetLine.direction = (max_distance - global_position).normalized() * -1 $TargetLine.rotation = -rotation $TargetLine.queue_redraw() if not anchor_mode: if OS.has_feature("mobile"): if process_touch: global_position = get_global_mouse_position() else: global_position = get_global_mouse_position() if is_instance_valid(arrow): arrow.rotation = rotation