2022-01-20 10:38:35 +00:00
|
|
|
class_name PlayerVehicleController
|
|
|
|
extends Node
|
|
|
|
|
2022-01-21 22:06:33 +00:00
|
|
|
export(NodePath) var input_sink_path = null
|
2022-01-20 10:38:35 +00:00
|
|
|
|
2022-01-21 22:06:33 +00:00
|
|
|
onready var _input_sink = get_node(input_sink_path)
|
2022-01-20 10:38:35 +00:00
|
|
|
|
|
|
|
|
2022-01-21 22:06:33 +00:00
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
var steering_sensitivity = GlobalSettings.steering_sensitivity
|
|
|
|
var return_speed = GlobalSettings.return_speed
|
|
|
|
var throttle_sensitivity = GlobalSettings.throttle_sensitivity
|
|
|
|
var brake_sensitivity = GlobalSettings.brake_sensitivity
|
|
|
|
var steering_deadzone_inner = GlobalSettings.steering_deadzone_inner
|
|
|
|
var steering_deadzone_outer = GlobalSettings.steering_deadzone_outer
|
|
|
|
|
|
|
|
_input_sink.inputs.throttle = move_toward(
|
|
|
|
_input_sink.inputs.throttle,
|
|
|
|
Input.get_action_strength("throttle"),
|
|
|
|
lerp(delta, 1, throttle_sensitivity)
|
|
|
|
)
|
|
|
|
_input_sink.inputs.clutch = Input.get_action_strength("clutch")
|
|
|
|
_input_sink.inputs.brake = move_toward(
|
|
|
|
_input_sink.inputs.brake,
|
|
|
|
Input.get_action_strength("brake"),
|
|
|
|
lerp(delta, 1, brake_sensitivity)
|
|
|
|
)
|
|
|
|
_input_sink.inputs.handbrake = Input.get_action_strength("handbrake")
|
2022-01-20 10:38:35 +00:00
|
|
|
var steering_input = (
|
|
|
|
Input.get_action_strength("steer_left")
|
|
|
|
- Input.get_action_strength("steer_right")
|
|
|
|
)
|
2022-01-21 22:06:33 +00:00
|
|
|
|
|
|
|
if abs(steering_input) <= steering_deadzone_inner:
|
2022-01-20 10:38:35 +00:00
|
|
|
steering_input = 0.0
|
2022-01-21 22:06:33 +00:00
|
|
|
|
|
|
|
if abs(steering_input) >= (1 - steering_deadzone_outer):
|
|
|
|
steering_input = 1.0 * sign(steering_input)
|
|
|
|
|
|
|
|
if (
|
|
|
|
abs(steering_input) > steering_deadzone_inner
|
|
|
|
and abs(steering_input) < (1 - steering_deadzone_outer)
|
|
|
|
):
|
|
|
|
steering_input = (
|
|
|
|
sign(steering_input)
|
|
|
|
* inverse_lerp(
|
|
|
|
steering_deadzone_inner, 1 - steering_deadzone_outer, abs(steering_input)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
var steering_factor = steering_sensitivity
|
|
|
|
if abs(_input_sink.inputs.steering) > abs(steering_input):
|
|
|
|
steering_factor *= return_speed
|
|
|
|
|
|
|
|
_input_sink.inputs.steering = move_toward(
|
|
|
|
_input_sink.inputs.steering, steering_input, lerp(delta, 1, steering_factor)
|
|
|
|
)
|
2022-01-20 10:38:35 +00:00
|
|
|
if Input.is_action_just_pressed("gear_up"):
|
2022-01-21 22:06:33 +00:00
|
|
|
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.UP
|
2022-01-21 15:55:27 +00:00
|
|
|
elif Input.is_action_just_pressed("gear_down"):
|
2022-01-21 22:06:33 +00:00
|
|
|
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.DOWN
|
2022-01-20 10:38:35 +00:00
|
|
|
else:
|
2022-01-21 22:06:33 +00:00
|
|
|
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.NONE
|