player controller logic
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
class_name PlayerController
|
||||
extends Node
|
||||
|
||||
@export var current_controlled : Boat:
|
||||
set(value):
|
||||
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
|
||||
|
||||
func _possess() -> void:
|
||||
camera_rig.target = current_controlled
|
||||
world_manager.focus = current_controlled
|
||||
hud.boat = current_controlled
|
||||
Reference in New Issue
Block a user