sparkygd/scripts/aircraft/nodes/flight_sim_controller.gd

44 lines
1.8 KiB
GDScript3
Raw Normal View History

2025-09-03 18:24:08 -04:00
class_name FlightSimController
extends AircraftController
@export var pitch_down := &"pitch_down"
@export var pitch_up := &"pitch_up"
@export var yaw_left := &"yaw_left"
@export var yaw_right := &"yaw_right"
@export var roll_left := &"roll_left"
@export var roll_right := &"roll_right"
@export var throttle_down := &"throttle_down"
@export var throttle_up := &"throttle_up"
@export var pitch_speed := 1.0
@export var yaw_speed := 1.0
@export var roll_speed := 1.0
@export var throttle_speed := 1.0
#func _ready() -> void:
# Only process for the local player.
# set_process(get_multiplayer_authority() == multiplayer.get_unique_id())
# if get_multiplayer_authority() == multiplayer.get_unique_id():
# print("Multiplayer auth: ", str(get_multiplayer_authority()))
func _process(delta: float) -> void:
2025-09-03 18:24:08 -04:00
if get_multiplayer_authority() == multiplayer.get_unique_id():
var pitch_target := Input.get_axis(pitch_down, pitch_up)
var pitch_diff := pitch_target - pitch
pitch += signf(pitch_diff) * minf(absf(pitch_diff), pitch_speed * delta)
var yaw_target := Input.get_axis(yaw_left, yaw_right)
var yaw_diff := yaw_target - yaw
yaw += signf(yaw_diff) * minf(absf(yaw_diff), yaw_speed * delta)
var roll_target := Input.get_axis(roll_left, roll_right)
var roll_diff := roll_target - roll
roll += signf(roll_diff) * minf(absf(roll_diff), roll_speed * delta)
var throttle_target := Input.get_axis(throttle_down, throttle_up) * 0.5 + 0.5
if throttle_target > throttle:
throttle = minf(throttle_target, throttle + throttle_speed * delta)
elif throttle_target < throttle:
throttle = maxf(throttle_target, throttle - throttle_speed * delta)
brake = 1.0 if throttle < 0.05 else 0.0