class_name PlayerController extends Node @export var current_controlled : Boat: set(value): if current_controlled != null and current_controlled != value: current_controlled.desired_throttle = 0.0 current_controlled.steer_input = 0.0 current_controlled.fire_intents.clear() current_controlled = value if is_node_ready(): if current_controlled != null: desired_throttle = current_controlled.throttle _possess() @export var world_manager : WorldManager: set(value): world_manager = value if is_node_ready(): _possess() @export var camera_rig : CameraRig: set(value): camera_rig = value if is_node_ready(): _possess() @export var hud : Hud: set(value): hud = value if is_node_ready(): _possess() @export var throttle_ramp := 0.5 var desired_throttle := 0.0 func _ready() -> void: if current_controlled != null: # Only happens on intial loading if boat already moves desired_throttle = current_controlled.throttle _possess() func _process(delta: float) -> void: if current_controlled == null: return if Input.is_action_pressed("throttle_increase"): desired_throttle = move_toward(desired_throttle, 1, throttle_ramp * delta) elif Input.is_action_pressed("throttle_decrease"): desired_throttle = move_toward(desired_throttle, -1, throttle_ramp * delta) elif Input.is_action_pressed("throttle_stop"): desired_throttle = 0.0 var steer_input := Input.get_axis("rudder_right", "rudder_left") current_controlled.desired_throttle = desired_throttle current_controlled.steer_input = steer_input current_controlled.fire_intents[0] = Input.is_action_pressed("fire") func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed(&"debug_possess_next"): _possess_next() func _possess() -> void: if camera_rig != null: camera_rig.target = current_controlled if world_manager != null: world_manager.focus = current_controlled if hud != null: hud.boat = current_controlled func _possess_next() -> void: var boats := get_tree().get_nodes_in_group(&"boats") if boats.is_empty(): current_controlled = null return var idx := boats.find(current_controlled) current_controlled = boats[(idx + 1) % boats.size()]