69 lines
1.8 KiB
GDScript
69 lines
1.8 KiB
GDScript
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 = 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
|
|
|
|
if Input.is_action_pressed("fire"):
|
|
current_controlled.fire_weapons()
|
|
|
|
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
|