Add more control settings

pull/2/head
Ensar Sarajčić 2022-01-21 23:06:33 +01:00
parent ef77b64c96
commit 61b7139aa8
9 changed files with 489 additions and 149 deletions

View File

@ -1,25 +1,50 @@
extends Panel
const PLAYER_CONTROLLER = preload("res://player/vehicle_controller.gd")
var inputs = BuggedVehicle.VehicleInputs.new()
onready var master_bus := AudioServer.get_bus_index("Master")
onready var sound_bus := AudioServer.get_bus_index("Sound")
onready var music_bus := AudioServer.get_bus_index("Music")
# gdlint: ignore=max-line-length
onready var master_slider: HSlider = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/MasterSlider
onready var master_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Audio/Audio/MasterSlider
# gdlint: ignore=max-line-length
onready var sound_slider: HSlider = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/SoundEffectsSlider
onready var sound_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Audio/Audio/SoundEffectsSlider
# gdlint: ignore=max-line-length
onready var music_slider: HSlider = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/MusicSlider
onready var music_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Audio/Audio/MusicSlider
# gdlint: ignore=max-line-length
onready var auto_clutch_cb: CheckBox = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/AutoClutchCheckBox
onready var auto_clutch_cb: CheckBox = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/AutoClutchCheckBox
# gdlint: ignore=max-line-length
onready var automatic_transmission_cb: CheckBox = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/AutomaticTransmissionCheckBox
onready var automatic_transmission_cb: CheckBox = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/AutomaticTransmissionCheckBox
# gdlint: ignore=max-line-length
onready var fullscreen_cb: CheckBox = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/FullscreenCheckBox
onready var fullscreen_cb: CheckBox = $MarginContainer/VSplitContainer/TabContainer/Video/Video/FullscreenCheckBox
# gdlint: ignore=max-line-length
onready var borderless_cb: CheckBox = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/BorderlessCheckBox
onready var borderless_cb: CheckBox = $MarginContainer/VSplitContainer/TabContainer/Video/Video/BorderlessCheckBox
# gdlint: ignore=max-line-length
onready var multiplayer_name_box: LineEdit = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/MultiplayerNameBox
onready var multiplayer_name_box: LineEdit = $MarginContainer/VSplitContainer/TabContainer/Gameplay/Gameplay/MultiplayerNameBox
# gdlint: ignore=max-line-length
onready var steering_sensitivity_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringSensitivitySlider
# gdlint: ignore=max-line-length
onready var steering_return_speed_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringReturnSpeedSlider
# gdlint: ignore=max-line-length
onready var steering_deadzone_inner_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringInnerDeadzoneSlider
# gdlint: ignore=max-line-length
onready var steering_deadzone_outer_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringOuterDeadzoneSlider
# gdlint: ignore=max-line-length
onready var throttle_sensitivity_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/ThrottleSensitivitySlider
# gdlint: ignore=max-line-length
onready var brakes_sensitivity_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/BrakesSensitivitySlider
# gdlint: ignore=max-line-length
onready var steering_value_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Steering/HSlider
# gdlint: ignore=max-line-length
onready var throttle_value_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Throttle/HSlider
# gdlint: ignore=max-line-length
onready var brakes_value_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Brakes/HSlider
# gdlint: ignore=max-line-length
onready var gear_value_slider: HSlider = $MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Gear/HSlider
func _ready() -> void:
@ -30,14 +55,34 @@ func _ready() -> void:
auto_clutch_cb.pressed = GlobalSettings.auto_clutch
automatic_transmission_cb.pressed = GlobalSettings.automatic_transmission
multiplayer_name_box.text = GlobalSettings.multiplayer_name
steering_sensitivity_slider.value = GlobalSettings.steering_sensitivity
steering_return_speed_slider.value = GlobalSettings.return_speed
steering_deadzone_inner_slider.value = GlobalSettings.steering_deadzone_inner
steering_deadzone_outer_slider.value = GlobalSettings.steering_deadzone_outer
throttle_sensitivity_slider.value = GlobalSettings.throttle_sensitivity
brakes_sensitivity_slider.value = GlobalSettings.brake_sensitivity
fullscreen_cb.pressed = false
borderless_cb.pressed = false
var controller = PLAYER_CONTROLLER.new()
controller.input_sink_path = get_path()
add_child(controller)
if OS.is_window_fullscreen():
_set_fullscreen(true)
if OS.get_borderless_window():
_set_borderless(true)
func _physics_process(_delta: float) -> void:
steering_value_slider.value = -inputs.steering
throttle_value_slider.value = inputs.throttle
brakes_value_slider.value = inputs.brake
match inputs.gear_request:
BuggedVehicle.GearRequest.UP:
gear_value_slider.value += 1
BuggedVehicle.GearRequest.DOWN:
gear_value_slider.value -= 1
func _on_autoclutch_toggled(new_state: bool) -> void:
GlobalSettings.auto_clutch = new_state
@ -74,6 +119,30 @@ func _on_MusicSlider_value_changed(new_value: float) -> void:
AudioServer.set_bus_volume_db(music_bus, linear2db(new_value))
func _on_SteeringSensitivitySlider_value_changed(new_value: float) -> void:
GlobalSettings.steering_sensitivity = new_value
func _on_SteeringReturnSpeedSlider_value_changed(new_value: float) -> void:
GlobalSettings.return_speed = new_value
func _on_SteeringInnerDeadzoneSlider_value_changed(new_value: float) -> void:
GlobalSettings.steering_deadzone_inner = new_value
func _on_SteeringOuterDeadzoneSlider_value_changed(new_value: float) -> void:
GlobalSettings.steering_deadzone_outer = new_value
func _on_ThrottleSensitivitySlider_value_changed(new_value: float) -> void:
GlobalSettings.throttle_sensitivity = new_value
func _on_BrakesSensitivitySlider_value_changed(new_value: float) -> void:
GlobalSettings.brake_sensitivity = new_value
func _set_fullscreen(new_state: bool) -> void:
OS.set_window_fullscreen(new_state)
OS.set_window_maximized(new_state)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://assets/fonts/kenney-future-narrow.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://menu/settings_menu.gd" type="Script" id=2]
@ -8,16 +8,12 @@
size = 64
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=4]
size = 24
[sub_resource type="DynamicFont" id=5]
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=3]
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=5]
font_data = ExtResource( 1 )
[node name="SettingsMenu" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -37,7 +33,7 @@ margin_bottom = -20.0
[node name="VSplitContainer" type="VSplitContainer" parent="MarginContainer"]
margin_right = 984.0
margin_bottom = 705.0
margin_bottom = 560.0
dragger_visibility = 1
[node name="HSplitContainer" type="HSplitContainer" parent="MarginContainer/VSplitContainer"]
@ -59,52 +55,27 @@ text = "Settings"
align = 1
valign = 1
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VSplitContainer"]
[node name="TabContainer" type="TabContainer" parent="MarginContainer/VSplitContainer"]
margin_top = 96.0
margin_right = 984.0
margin_bottom = 705.0
margin_bottom = 560.0
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VSplitContainer/CenterContainer"]
margin_left = 356.0
margin_right = 627.0
margin_bottom = 609.0
[node name="Gameplay" type="ScrollContainer" parent="MarginContainer/VSplitContainer/TabContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 72.0
margin_right = -8.0
margin_bottom = -8.0
[node name="Gameplay" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_right = 271.0
margin_bottom = 27.0
custom_fonts/font = SubResource( 4 )
text = "Gameplay"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Gameplay" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Gameplay"]
margin_right = 968.0
margin_bottom = 82.0
size_flags_horizontal = 3
[node name="AutoClutchCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 35.0
margin_right = 271.0
margin_bottom = 83.0
custom_fonts/font = SubResource( 3 )
text = "Automatic Clutch"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AutomaticTransmissionCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 91.0
margin_right = 271.0
margin_bottom = 139.0
custom_fonts/font = SubResource( 3 )
text = "Automatic Transmission"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MultiplayerNameLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 147.0
margin_right = 271.0
margin_bottom = 165.0
[node name="MultiplayerNameLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Gameplay/Gameplay"]
margin_right = 968.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 5 )
text = "Multiplayer name"
align = 1
@ -112,26 +83,31 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="MultiplayerNameBox" type="LineEdit" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 173.0
margin_right = 271.0
margin_bottom = 229.0
[node name="MultiplayerNameBox" type="LineEdit" parent="MarginContainer/VSplitContainer/TabContainer/Gameplay/Gameplay"]
margin_top = 26.0
margin_right = 968.0
margin_bottom = 82.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AudioLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 237.0
margin_right = 271.0
margin_bottom = 264.0
custom_fonts/font = SubResource( 4 )
text = "Audio"
align = 1
[node name="Audio" type="ScrollContainer" parent="MarginContainer/VSplitContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 72.0
margin_right = -8.0
margin_bottom = -8.0
[node name="MasterLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 272.0
margin_right = 271.0
margin_bottom = 290.0
[node name="Audio" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Audio"]
margin_right = 968.0
margin_bottom = 190.0
size_flags_horizontal = 3
[node name="MasterLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_right = 968.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 5 )
text = "Master"
align = 1
@ -139,10 +115,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="MasterSlider" type="HSlider" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 298.0
margin_right = 271.0
margin_bottom = 330.0
[node name="MasterSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_top = 26.0
margin_right = 968.0
margin_bottom = 58.0
max_value = 1.0
step = 0.05
value = 1.0
@ -150,10 +126,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="SoundEffectsLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 338.0
margin_right = 271.0
margin_bottom = 356.0
[node name="SoundEffectsLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_top = 66.0
margin_right = 968.0
margin_bottom = 84.0
custom_fonts/font = SubResource( 5 )
text = "Sound Effects"
align = 1
@ -161,10 +137,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="SoundEffectsSlider" type="HSlider" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 364.0
margin_right = 271.0
margin_bottom = 396.0
[node name="SoundEffectsSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_top = 92.0
margin_right = 968.0
margin_bottom = 124.0
max_value = 1.0
step = 0.05
value = 1.0
@ -172,10 +148,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="MusicLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 404.0
margin_right = 271.0
margin_bottom = 422.0
[node name="MusicLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_top = 132.0
margin_right = 968.0
margin_bottom = 150.0
custom_fonts/font = SubResource( 5 )
text = "Music"
align = 1
@ -183,10 +159,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="MusicSlider" type="HSlider" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 430.0
margin_right = 271.0
margin_bottom = 462.0
[node name="MusicSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Audio/Audio"]
margin_top = 158.0
margin_right = 968.0
margin_bottom = 190.0
max_value = 1.0
step = 0.05
value = 1.0
@ -194,18 +170,23 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="VideoLabel" type="Label" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 470.0
margin_right = 271.0
margin_bottom = 497.0
custom_fonts/font = SubResource( 4 )
text = "Video"
align = 1
[node name="Video" type="ScrollContainer" parent="MarginContainer/VSplitContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 72.0
margin_right = -8.0
margin_bottom = -8.0
[node name="FullscreenCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 505.0
margin_right = 271.0
margin_bottom = 553.0
[node name="Video" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Video"]
margin_right = 968.0
margin_bottom = 104.0
size_flags_horizontal = 3
[node name="FullscreenCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/TabContainer/Video/Video"]
margin_right = 968.0
margin_bottom = 48.0
custom_fonts/font = SubResource( 3 )
text = "Fullscreen"
align = 1
@ -213,10 +194,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="BorderlessCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer"]
margin_top = 561.0
margin_right = 271.0
margin_bottom = 609.0
[node name="BorderlessCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/TabContainer/Video/Video"]
margin_top = 56.0
margin_right = 968.0
margin_bottom = 104.0
custom_fonts/font = SubResource( 3 )
text = "Borderless"
align = 1
@ -224,11 +205,272 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Controls" type="ScrollContainer" parent="MarginContainer/VSplitContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 72.0
margin_right = -8.0
margin_bottom = -8.0
[node name="Controls" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls"]
margin_right = 968.0
margin_bottom = 566.0
size_flags_horizontal = 3
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_right = 944.0
margin_bottom = 58.0
[node name="Steering" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer"]
margin_right = 230.0
margin_bottom = 58.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Steering"]
margin_right = 230.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 3 )
text = "Steering"
[node name="HSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Steering"]
margin_top = 26.0
margin_right = 230.0
margin_bottom = 58.0
min_value = -1.0
max_value = 1.0
step = 0.01
editable = false
[node name="Throttle" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer"]
margin_left = 238.0
margin_right = 468.0
margin_bottom = 58.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Throttle"]
margin_right = 230.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 3 )
text = "Throttle"
[node name="HSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Throttle"]
margin_top = 26.0
margin_right = 230.0
margin_bottom = 58.0
max_value = 1.0
step = 0.01
editable = false
[node name="Brakes" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer"]
margin_left = 476.0
margin_right = 706.0
margin_bottom = 58.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Brakes"]
margin_right = 230.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 3 )
text = "Brakes"
[node name="HSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Brakes"]
margin_top = 26.0
margin_right = 230.0
margin_bottom = 58.0
max_value = 1.0
step = 0.01
editable = false
[node name="Gear" type="VBoxContainer" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer"]
margin_left = 714.0
margin_right = 944.0
margin_bottom = 58.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Gear"]
margin_right = 230.0
margin_bottom = 18.0
custom_fonts/font = SubResource( 3 )
text = "Gear"
[node name="HSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/HBoxContainer/Gear"]
margin_top = 26.0
margin_right = 230.0
margin_bottom = 58.0
min_value = -1.0
max_value = 6.0
editable = false
[node name="AutoClutchCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 66.0
margin_right = 944.0
margin_bottom = 114.0
custom_fonts/font = SubResource( 3 )
text = "Automatic Clutch"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AutomaticTransmissionCheckBox" type="CheckBox" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 122.0
margin_right = 944.0
margin_bottom = 170.0
custom_fonts/font = SubResource( 3 )
text = "Automatic Transmission"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringSensitivityLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 178.0
margin_right = 944.0
margin_bottom = 196.0
custom_fonts/font = SubResource( 5 )
text = "Steering Sensitivity"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringSensitivitySlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 204.0
margin_right = 944.0
margin_bottom = 236.0
min_value = 0.01
max_value = 1.0
step = 0.01
value = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringInnerDeadzoneLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 244.0
margin_right = 944.0
margin_bottom = 262.0
custom_fonts/font = SubResource( 5 )
text = "Steering Inner Deadzone"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringInnerDeadzoneSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 270.0
margin_right = 944.0
margin_bottom = 302.0
max_value = 0.4
step = 0.01
value = 0.4
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringOuterDeadzoneLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 310.0
margin_right = 944.0
margin_bottom = 328.0
custom_fonts/font = SubResource( 5 )
text = "Steering Outer Deadzone"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringOuterDeadzoneSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 336.0
margin_right = 944.0
margin_bottom = 368.0
max_value = 0.4
step = 0.01
value = 0.4
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringReturnSpeedLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 376.0
margin_right = 944.0
margin_bottom = 394.0
custom_fonts/font = SubResource( 5 )
text = "Steering Return Speed"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SteeringReturnSpeedSlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 402.0
margin_right = 944.0
margin_bottom = 434.0
max_value = 60.0
step = 0.01
value = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ThrottleSensitivityLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 442.0
margin_right = 944.0
margin_bottom = 460.0
custom_fonts/font = SubResource( 5 )
text = "Throttle Sensitivity"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ThrottleSensitivitySlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 468.0
margin_right = 944.0
margin_bottom = 500.0
min_value = 0.01
max_value = 1.0
step = 0.01
value = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="BrakesSensitivityLabel" type="Label" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 508.0
margin_right = 944.0
margin_bottom = 526.0
custom_fonts/font = SubResource( 5 )
text = "Brakes Sensitivity"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="BrakesSensitivitySlider" type="HSlider" parent="MarginContainer/VSplitContainer/TabContainer/Controls/Controls"]
margin_top = 534.0
margin_right = 944.0
margin_bottom = 566.0
min_value = 0.01
max_value = 1.0
step = 0.01
value = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="MarginContainer/VSplitContainer/HSplitContainer/BackButton" to="." method="_on_BackButton_pressed"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/AutoClutchCheckBox" to="." method="_on_autoclutch_toggled"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/AutomaticTransmissionCheckBox" to="." method="_on_automatictransmission_toggled"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/MasterSlider" to="." method="_on_MasterSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/SoundEffectsSlider" to="." method="_on_SoundEffectsSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/MusicSlider" to="." method="_on_MusicSlider_value_changed"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/FullscreenCheckBox" to="." method="_on_fullscreen_toggled"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/BorderlessCheckBox" to="." method="_on_borderless_toggled"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Audio/Audio/MasterSlider" to="." method="_on_MasterSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Audio/Audio/SoundEffectsSlider" to="." method="_on_SoundEffectsSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Audio/Audio/MusicSlider" to="." method="_on_MusicSlider_value_changed"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/TabContainer/Video/Video/FullscreenCheckBox" to="." method="_on_fullscreen_toggled"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/TabContainer/Video/Video/BorderlessCheckBox" to="." method="_on_borderless_toggled"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/AutoClutchCheckBox" to="." method="_on_autoclutch_toggled"]
[connection signal="toggled" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/AutomaticTransmissionCheckBox" to="." method="_on_automatictransmission_toggled"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringSensitivitySlider" to="." method="_on_SteeringSensitivitySlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringInnerDeadzoneSlider" to="." method="_on_SteeringInnerDeadzoneSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringOuterDeadzoneSlider" to="." method="_on_SteeringOuterDeadzoneSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/SteeringReturnSpeedSlider" to="." method="_on_SteeringReturnSpeedSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/ThrottleSensitivitySlider" to="." method="_on_ThrottleSensitivitySlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VSplitContainer/TabContainer/Controls/Controls/BrakesSensitivitySlider" to="." method="_on_BrakesSensitivitySlider_value_changed"]

View File

@ -1,27 +1,65 @@
class_name PlayerVehicleController
extends Node
export(NodePath) var vehicle_path = null
export(NodePath) var input_sink_path = null
onready var _vehicle: BuggedVehicle = get_node(vehicle_path)
onready var _input_sink = get_node(input_sink_path)
func _physics_process(_delta: float) -> void:
_vehicle.inputs.throttle = Input.get_action_strength("throttle")
_vehicle.inputs.clutch = Input.get_action_strength("clutch")
_vehicle.inputs.brake = Input.get_action_strength("brake")
_vehicle.inputs.handbrake = Input.get_action_strength("handbrake")
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")
var steering_input = (
Input.get_action_strength("steer_left")
- Input.get_action_strength("steer_right")
)
# TODO: deadzone config
if abs(steering_input) < 0.05:
if abs(steering_input) <= steering_deadzone_inner:
steering_input = 0.0
_vehicle.inputs.steering = steering_input
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):
print("detected returning: %s, %s" % [steering_factor, return_speed])
steering_factor *= return_speed
print("updated turn speed: %s" % steering_factor)
_input_sink.inputs.steering = move_toward(
_input_sink.inputs.steering, steering_input, lerp(delta, 1, steering_factor)
)
if Input.is_action_just_pressed("gear_up"):
_vehicle.inputs.gear_request = BuggedVehicle.GearRequest.UP
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.UP
elif Input.is_action_just_pressed("gear_down"):
_vehicle.inputs.gear_request = BuggedVehicle.GearRequest.DOWN
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.DOWN
else:
_vehicle.inputs.gear_request = BuggedVehicle.GearRequest.NONE
_input_sink.inputs.gear_request = BuggedVehicle.GearRequest.NONE

View File

@ -52,7 +52,7 @@ func _spawn_in_player():
add_child(player_node)
add_child(gui)
player_controller = PLAYER_CONTROLLER.new()
player_controller.vehicle_path = player_node.get_path()
player_controller.input_sink_path = player_node.get_path()
player_node.add_child(player_controller)
camera_controller = CAMERA_CONTROLLER.new()
camera_controller.attach_cameras_to(player_node)

View File

@ -2,6 +2,13 @@ extends Node
var auto_clutch: bool = false
var automatic_transmission: bool = true
var steering_sensitivity = 1.0
var return_speed = 2.0
var throttle_sensitivity = 1.0
var brake_sensitivity = 1.0
var steering_deadzone_inner = 0.0
var steering_deadzone_outer = 0.0
var selected_camera: int = 0
var multiplayer_name: String = "Player"

View File

@ -48,10 +48,7 @@ rings = 3
[node name="beetlecar" groups=["car"] instance=ExtResource( 2 )]
mass = 340.0
script = ExtResource( 1 )
max_steer_angle = 18.0
speed_steer_angle = 8.0
max_steer_speed = 60.0
max_steer_input = 60.0
max_steer_input = 40.0
max_engine_force = 100.0
max_brake_force = 60.0
base_engine_pitch = 0.38
@ -91,6 +88,7 @@ script = ExtResource( 5 )
needle_path = NodePath("speed_needle")
[node name="steering_controller" parent="chassis/cockpit" index="5"]
transform = Transform( -5.15093, 0, -4.50309e-07, 0, 5.15093, 0, 4.50309e-07, 0, -5.15093, 0.591791, 0.882535, 1.0757 )
script = ExtResource( 6 )
[node name="rear_left" parent="." index="3"]

View File

@ -47,9 +47,6 @@ rings = 3
[node name="buggy" groups=["car"] instance=ExtResource( 1 )]
mass = 400.0
script = ExtResource( 3 )
max_steer_angle = 30.0
speed_steer_angle = 14.0
max_steer_speed = 120.0
max_engine_force = 160.0
max_brake_force = 80.0
throttle_power = 10000.0

View File

@ -55,10 +55,6 @@ rings = 3
[node name="bugmobile" groups=["car"] instance=ExtResource( 2 )]
mass = 600.0
script = ExtResource( 3 )
max_steer_angle = 16.0
speed_steer_angle = 8.0
max_steer_speed = 60.0
max_steer_input = 50.0
max_engine_force = 320.0
max_brake_force = 95.0
throttle_power = 8000.0

View File

@ -12,10 +12,7 @@ signal position_updated(player_id, position)
enum GearRequest { NONE, UP, DOWN }
export(float) var max_steer_angle = 25
export(float) var speed_steer_angle = 10
export(float) var max_steer_speed = 100.0
export(float) var max_steer_input = 80.0
export(float) var max_steer_input = 30
export(float) var max_engine_force = 85.0
export(float) var max_brake_force = 50.0
@ -59,8 +56,6 @@ onready var rlsmoke: TireSmoke = $rl_tire_smoke
onready var engine_sound_player: AudioStreamPlayer3D = $engine_sound_player
onready var engine_sound_playback: AudioStreamPlayback = $engine_sound_player.get_stream_playback()
onready var max_steer_angle_rad: float = deg2rad(max_steer_angle)
onready var speed_steer_angle_rad: float = deg2rad(speed_steer_angle)
onready var max_steer_input_rad: float = deg2rad(max_steer_input)
onready var auto_clutch_rpm_limit = max_rpm * automatic_gear_down_threshold
@ -250,12 +245,10 @@ func _physics_process(delta: float):
emit_signal("speed_updated", speed, speed / expected_max_speed)
emit_signal("rpm_updated", rpm, rpm_factor)
var steering_input = inputs.steering
var steering_input = inputs.steering * max_steer_input_rad
var steer_speed_factor = clamp(speed / max_steer_speed, 0.0, 1.0)
steering = steering_input * lerp(max_steer_angle_rad, speed_steer_angle_rad, steer_speed_factor)
emit_signal("steering_updated", steering, steering / max_steer_angle_rad)
steering = clamp(steering_input, -max_steer_input_rad, max_steer_input_rad)
emit_signal("steering_updated", steering, steering / max_steer_input_rad)
emit_signal("position_updated", get_network_master(), global_transform)