diff --git a/assets/Black Metal.material b/assets/Black Metal.material index c824924..4619833 100644 Binary files a/assets/Black Metal.material and b/assets/Black Metal.material differ diff --git a/assets/ChassiBlackMetal.material b/assets/ChassiBlackMetal.material index 05b6860..d27a4d2 100644 Binary files a/assets/ChassiBlackMetal.material and b/assets/ChassiBlackMetal.material differ diff --git a/assets/Chassis Metal.material b/assets/Chassis Metal.material index fc11560..0467a9c 100644 Binary files a/assets/Chassis Metal.material and b/assets/Chassis Metal.material differ diff --git a/assets/Chassis.material b/assets/Chassis.material index ea4e3fd..ecd6a1f 100644 Binary files a/assets/Chassis.material and b/assets/Chassis.material differ diff --git a/assets/ChassisRedMetal.material b/assets/ChassisRedMetal.material index cee6529..3011f5c 100644 Binary files a/assets/ChassisRedMetal.material and b/assets/ChassisRedMetal.material differ diff --git a/assets/ChassisWhiteMetal.material b/assets/ChassisWhiteMetal.material index eec93f0..b46c60b 100644 Binary files a/assets/ChassisWhiteMetal.material and b/assets/ChassisWhiteMetal.material differ diff --git a/assets/Cloth.material b/assets/Cloth.material index c410f33..6e435be 100644 Binary files a/assets/Cloth.material and b/assets/Cloth.material differ diff --git a/assets/Cockpit.material b/assets/Cockpit.material new file mode 100644 index 0000000..ce8d0f2 Binary files /dev/null and b/assets/Cockpit.material differ diff --git a/assets/DarkGlass.material b/assets/DarkGlass.material new file mode 100644 index 0000000..891509d Binary files /dev/null and b/assets/DarkGlass.material differ diff --git a/assets/Engine.material b/assets/Engine.material index 243a792..8ec054c 100644 Binary files a/assets/Engine.material and b/assets/Engine.material differ diff --git a/assets/Glass.material b/assets/Glass.material index 17fe669..31bc6f8 100644 Binary files a/assets/Glass.material and b/assets/Glass.material differ diff --git a/assets/Metal.material b/assets/Metal.material index 0324386..1acdcd6 100644 Binary files a/assets/Metal.material and b/assets/Metal.material differ diff --git a/assets/Rims.material b/assets/Rims.material index 47c6bbf..6d7f1c4 100644 Binary files a/assets/Rims.material and b/assets/Rims.material differ diff --git a/assets/Tyre Black.material b/assets/Tyre Black.material index 4b47329..737da42 100644 Binary files a/assets/Tyre Black.material and b/assets/Tyre Black.material differ diff --git a/assets/Tyre White.material b/assets/Tyre White.material index ca815de..3139527 100644 Binary files a/assets/Tyre White.material and b/assets/Tyre White.material differ diff --git a/assets/Tyre.material b/assets/Tyre.material index 326924d..94e3502 100644 Binary files a/assets/Tyre.material and b/assets/Tyre.material differ diff --git a/assets/basic_buggy.glb b/assets/basic_buggy.glb index 4f7e447..81a4643 100644 Binary files a/assets/basic_buggy.glb and b/assets/basic_buggy.glb differ diff --git a/assets/beetlecar.glb b/assets/beetlecar.glb index d848163..d7aa7c2 100644 Binary files a/assets/beetlecar.glb and b/assets/beetlecar.glb differ diff --git a/assets/bugmobile.glb b/assets/bugmobile.glb index dd49b96..008e72a 100644 Binary files a/assets/bugmobile.glb and b/assets/bugmobile.glb differ diff --git a/assets/meterbg.material b/assets/meterbg.material new file mode 100644 index 0000000..a0191b3 Binary files /dev/null and b/assets/meterbg.material differ diff --git a/assets/red_needle.material b/assets/red_needle.material new file mode 100644 index 0000000..0d0928d Binary files /dev/null and b/assets/red_needle.material differ diff --git a/assets/source/basic_buggy.blend b/assets/source/basic_buggy.blend index 2d5c46f..b580764 100644 Binary files a/assets/source/basic_buggy.blend and b/assets/source/basic_buggy.blend differ diff --git a/assets/source/beetlecar.blend b/assets/source/beetlecar.blend index 2deba02..9c0b7f0 100644 Binary files a/assets/source/beetlecar.blend and b/assets/source/beetlecar.blend differ diff --git a/assets/source/bugmobile.blend b/assets/source/bugmobile.blend index a2e2ef2..be2abd5 100644 Binary files a/assets/source/bugmobile.blend and b/assets/source/bugmobile.blend differ diff --git a/player/cameras/camera_controller.gd b/player/cameras/camera_controller.gd new file mode 100644 index 0000000..de8d45a --- /dev/null +++ b/player/cameras/camera_controller.gd @@ -0,0 +1,43 @@ +class_name CameraController +extends Reference + +const FOLLOW_CAMERA = preload("res://player/cameras/follow_camera.tscn") +const STATIC_CAMERA = preload("res://player/cameras/static_camera.tscn") + +var _cameras = [] + + +func attach_cameras_to(player_node: BuggedVehicle) -> void: + var cockpit_camera = STATIC_CAMERA.instance() + player_node.get_cockpit_position().add_child(cockpit_camera) + cockpit_camera.rotate(Vector3.UP, deg2rad(180)) + var follow_camera = FOLLOW_CAMERA.instance() + follow_camera.global_transform = player_node.global_transform.translated( + -player_node.global_transform.basis.z * 100 + ) + follow_camera.follow_target_path = player_node.get_path() + player_node.get_parent().add_child(follow_camera) + var bumpera_camera = STATIC_CAMERA.instance() + player_node.get_bumper_position().add_child(bumpera_camera) + bumpera_camera.rotate(Vector3.UP, deg2rad(180)) + var hood_camera = STATIC_CAMERA.instance() + player_node.get_hood_position().add_child(hood_camera) + hood_camera.rotate(Vector3.UP, deg2rad(180)) + var static_follow_camera = STATIC_CAMERA.instance() + player_node.get_static_follow_position().add_child(static_follow_camera) + static_follow_camera.rotate(Vector3.UP, deg2rad(180)) + _cameras = [follow_camera, cockpit_camera, hood_camera, bumpera_camera, static_follow_camera] + select_camera(GlobalSettings.selected_camera) + + +func select_camera(camera_index: int) -> void: + var select_index = camera_index + if camera_index < 0 or camera_index >= _cameras.size(): + select_index = 0 + + GlobalSettings.selected_camera = select_index + _cameras[select_index].current = true + + +func next_camera() -> void: + select_camera(GlobalSettings.selected_camera + 1) diff --git a/player/camera.gd b/player/cameras/follow_camera.gd similarity index 100% rename from player/camera.gd rename to player/cameras/follow_camera.gd diff --git a/player/camera.tscn b/player/cameras/follow_camera.tscn similarity index 73% rename from player/camera.tscn rename to player/cameras/follow_camera.tscn index 309b6cc..e2ac8c3 100644 --- a/player/camera.tscn +++ b/player/cameras/follow_camera.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=2] -[ext_resource path="res://player/camera.gd" type="Script" id=1] +[ext_resource path="res://player/cameras/follow_camera.gd" type="Script" id=1] [node name="camera" type="Camera"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.88022, 23.0639 ) diff --git a/player/cameras/static_camera.tscn b/player/cameras/static_camera.tscn new file mode 100644 index 0000000..071ba76 --- /dev/null +++ b/player/cameras/static_camera.tscn @@ -0,0 +1,4 @@ +[gd_scene format=2] + +[node name="camera" type="Camera"] +far = 1000.0 diff --git a/project.godot b/project.godot index 11a9d65..8d9ec1e 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://vehicles/vehicle.gd" }, { +"base": "Reference", +"class": "CameraController", +"language": "GDScript", +"path": "res://player/cameras/camera_controller.gd" +}, { "base": "Particles", "class": "TireSmoke", "language": "GDScript", @@ -32,6 +37,7 @@ _global_script_classes=[ { _global_script_class_icons={ "BaseTrackLevel": "", "BuggedVehicle": "", +"CameraController": "", "TireSmoke": "", "Track": "" } @@ -124,6 +130,12 @@ reset_vehicle={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null) ] } +next_camera={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":70,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":false,"script":null) + ] +} [physics] diff --git a/scenes/base_track_level.gd b/scenes/base_track_level.gd index 932211c..970306f 100644 --- a/scenes/base_track_level.gd +++ b/scenes/base_track_level.gd @@ -1,10 +1,11 @@ class_name BaseTrackLevel extends Spatial -const CAMERA = preload("res://player/camera.tscn") +const CAMERA_CONTROLLER = preload("res://player/cameras/camera_controller.gd") -var player_node: Node +var player_node: BuggedVehicle var gui: Node +var camera_controller: CameraController onready var track = $Track @@ -13,15 +14,11 @@ func _ready() -> void: reset_player_to(track.get_furthest_checkpoint(), player_node) add_child(player_node) add_child(gui) - var player_camera = CAMERA.instance() - player_camera.global_transform = player_node.global_transform.translated( - -player_node.global_transform.basis.z * 100 - ) - player_camera.follow_target_path = player_node.get_path() - add_child(player_camera) + camera_controller = CAMERA_CONTROLLER.new() + camera_controller.attach_cameras_to(player_node) -func spawn_player(player_node: Node, gui: Node) -> void: +func spawn_player(player_node: BuggedVehicle, gui: Node) -> void: self.player_node = player_node self.gui = gui @@ -40,6 +37,9 @@ func _process(_delta: float) -> void: if Input.is_action_just_released("reset_vehicle"): reset_player_to(track.get_furthest_checkpoint(), player_node) + if Input.is_action_just_released("next_camera"): + camera_controller.next_camera() + func _on_ResetArea_body_entered(body: Node) -> void: if body.get_groups().has("car"): diff --git a/settings/GlobalSettings.gd b/settings/GlobalSettings.gd index 7d54fb4..f392ac2 100644 --- a/settings/GlobalSettings.gd +++ b/settings/GlobalSettings.gd @@ -2,3 +2,4 @@ extends Node var auto_clutch: bool = false var automatic_transmission: bool = true +var selected_camera: int = 0 diff --git a/vehicles/beetlecar.tscn b/vehicles/beetlecar.tscn index dbb8924..4805dfe 100644 --- a/vehicles/beetlecar.tscn +++ b/vehicles/beetlecar.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=16 format=2] [ext_resource path="res://vehicles/vehicle.gd" type="Script" id=1] [ext_resource path="res://assets/beetlecar.glb" type="PackedScene" id=2] [ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=3] +[ext_resource path="res://vehicles/pedal.gd" type="Script" id=4] +[ext_resource path="res://vehicles/meter.gd" type="Script" id=5] +[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=6] [sub_resource type="Curve" id=3] _data = [ Vector2( 0, 0 ), 0.0, 3.60634, 0, 1, Vector2( 0.15566, 0.561364 ), 1.56017, 1.56017, 0, 0, Vector2( 0.830189, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ] @@ -70,6 +73,26 @@ suspension_stiffness = 12.0 damping_compression = 0.75 damping_relaxation = 0.8 +[node name="brake_pedal" parent="chassis/cockpit" index="0"] +script = ExtResource( 4 ) + +[node name="clutch_pedal" parent="chassis/cockpit" index="1"] +script = ExtResource( 4 ) + +[node name="gas_pedal" parent="chassis/cockpit" index="2"] +script = ExtResource( 4 ) + +[node name="rpm_meter" parent="chassis/cockpit" index="3"] +script = ExtResource( 5 ) +needle_path = NodePath("rpm_needle") + +[node name="speed_meter" parent="chassis/cockpit" index="4"] +script = ExtResource( 5 ) +needle_path = NodePath("speed_needle") + +[node name="steering_controller" parent="chassis/cockpit" index="5"] +script = ExtResource( 6 ) + [node name="rear_left" parent="." index="3"] transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, 0.621506, 0.375, -0.83483 ) use_as_traction = true @@ -139,3 +162,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.621508, 0.0502438, 1.19336 [node name="fl_tire_smoke" parent="." index="12" instance=ExtResource( 3 )] transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, 0.621506, 0.0502438, 1.19336 ) + +[node name="cockpit" type="Position3D" parent="." index="13"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.122976, 1.13133, 0.315432 ) + +[node name="hood" type="Position3D" parent="." index="14"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.01256, 0.87905 ) + +[node name="bumper" type="Position3D" parent="." index="15"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.535274, 1.89154 ) + +[node name="static_follow" type="Position3D" parent="." index="16"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.59115, -3.01375 ) + +[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"] +[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"] +[connection signal="rpm_updated" from="." to="chassis/cockpit/rpm_meter" method="_on_value_updated"] +[connection signal="speed_updated" from="." to="chassis/cockpit/speed_meter" method="_on_value_updated"] +[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"] +[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"] diff --git a/vehicles/buggy.tscn b/vehicles/buggy.tscn index 4a6455a..94833e1 100644 --- a/vehicles/buggy.tscn +++ b/vehicles/buggy.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=16 format=2] [ext_resource path="res://assets/basic_buggy.glb" type="PackedScene" id=1] [ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=2] [ext_resource path="res://vehicles/vehicle.gd" type="Script" id=3] +[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=4] +[ext_resource path="res://vehicles/meter.gd" type="Script" id=5] +[ext_resource path="res://vehicles/pedal.gd" type="Script" id=7] [sub_resource type="Curve" id=2] _data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.0660377, 0.243255 ), 0.0, 0.0, 0, 0, Vector2( 0.25, 0.563636 ), 4.02975, 4.02975, 0, 0, Vector2( 0.518868, 0.761364 ), 3.22818, 3.22818, 0, 0, Vector2( 0.849057, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ] @@ -58,6 +61,33 @@ sound_curve = SubResource( 4 ) automatic_gear_up_threshold = 0.85 automatic_gear_down_threshold = 0.4 +[node name="brake_pedal" parent="chassis/cockpit" index="0"] +script = ExtResource( 7 ) + +[node name="clutch_pedal" parent="chassis/cockpit" index="1"] +script = ExtResource( 7 ) + +[node name="gas_pedal" parent="chassis/cockpit" index="2"] +script = ExtResource( 7 ) + +[node name="rpm_meter" parent="chassis/cockpit" index="3"] +transform = Transform( 1, 0, 0, 0, 0.351842, 0.93606, 0, -0.93606, 0.351842, 0.036114, 0.360487, 0.695986 ) +script = ExtResource( 5 ) +needle_path = NodePath("rpm_needle") + +[node name="rpm_needle" parent="chassis/cockpit/rpm_meter" index="0"] +transform = Transform( 1, 0, 0, 0, 0.351842, -0.93606, 0, 0.93606, 0.351842, -0.000453245, 0.000504017, -0.00276601 ) + +[node name="speed_meter" parent="chassis/cockpit" index="4"] +script = ExtResource( 5 ) +needle_path = NodePath("speed_needle") + +[node name="speed_needle" parent="chassis/cockpit/speed_meter" index="0"] +transform = Transform( 1, 0, 0, 0, 0.351841, -0.93606, 0, 0.93606, 0.351841, -0.00056617, 0.000744879, -0.00399888 ) + +[node name="steering_controller" parent="chassis/cockpit" index="5"] +script = ExtResource( 4 ) + [node name="front_left" parent="." index="1"] use_as_traction = true use_as_steering = true @@ -139,3 +169,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.950753, -0.0380455, -1.41438 [node name="rr_tire_smoke" parent="." index="12" instance=ExtResource( 2 )] transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, -0.950755, -0.038045, -1.41438 ) + +[node name="cockpit" type="Position3D" parent="." index="13"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44962, 0.200323 ) + +[node name="hood" type="Position3D" parent="." index="14"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31056, 0.894584 ) + +[node name="bumper" type="Position3D" parent="." index="15"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.811448, 1.79879 ) + +[node name="static_follow" type="Position3D" parent="." index="16"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.15146, -4.84184 ) + +[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"] +[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"] +[connection signal="rpm_updated" from="." to="chassis/cockpit/rpm_meter" method="_on_value_updated"] +[connection signal="speed_updated" from="." to="chassis/cockpit/speed_meter" method="_on_value_updated"] +[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"] +[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"] diff --git a/vehicles/bugmobile.tscn b/vehicles/bugmobile.tscn index d352ee0..8baaca5 100644 --- a/vehicles/bugmobile.tscn +++ b/vehicles/bugmobile.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/bugmobile.glb" type="PackedScene" id=2] [ext_resource path="res://vehicles/vehicle.gd" type="Script" id=3] +[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=4] +[ext_resource path="res://vehicles/pedal.gd" type="Script" id=5] +[ext_resource path="res://vehicles/meter.gd" type="Script" id=6] [sub_resource type="Curve" id=18] _data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.179245, 0.584091 ), 4.91185, 4.91185, 0, 0, Vector2( 0.603774, 0.954545 ), 6.05975, 6.05975, 0, 0, Vector2( 0.806604, 0.989773 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ] @@ -89,6 +92,26 @@ suspension_max_force = 7000.0 damping_compression = 0.9 damping_relaxation = 0.92 +[node name="brake_pedal" parent="chassis/cockpit" index="0"] +script = ExtResource( 5 ) + +[node name="clutch_pedal" parent="chassis/cockpit" index="1"] +script = ExtResource( 5 ) + +[node name="gas_pedal" parent="chassis/cockpit" index="2"] +script = ExtResource( 5 ) + +[node name="steering_controller" parent="chassis/cockpit" index="3"] +script = ExtResource( 4 ) + +[node name="rpm_meter" parent="chassis/cockpit/steering_controller" index="0"] +script = ExtResource( 6 ) +needle_path = NodePath("rpm_needle") + +[node name="speed_meter" parent="chassis/cockpit/steering_controller" index="1"] +script = ExtResource( 6 ) +needle_path = NodePath("speed_needle") + [node name="front_right" parent="." index="4"] use_as_steering = true wheel_radius = 0.35 @@ -138,3 +161,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.18159, 0.117865, -1.93644 ) [node name="rr_tire_smoke" parent="." index="12" instance=ExtResource( 1 )] transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, -1.02536, 0.101852, -1.93766 ) + +[node name="cockpit" type="Position3D" parent="." index="13"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.03657, 0 ) + +[node name="hood" type="Position3D" parent="." index="14"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.00873, 0.756477 ) + +[node name="bumper" type="Position3D" parent="." index="15"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.605405, 1.5324 ) + +[node name="static_follow" type="Position3D" parent="." index="16"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.88984, -4.78212 ) + +[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"] +[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"] +[connection signal="rpm_updated" from="." to="chassis/cockpit/steering_controller/rpm_meter" method="_on_value_updated"] +[connection signal="speed_updated" from="." to="chassis/cockpit/steering_controller/speed_meter" method="_on_value_updated"] +[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"] +[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"] diff --git a/vehicles/meter.gd b/vehicles/meter.gd new file mode 100644 index 0000000..3edd590 --- /dev/null +++ b/vehicles/meter.gd @@ -0,0 +1,12 @@ +extends MeshInstance + +export(float) var min_angle = -90 +export(float) var max_angle = 90 +export(NodePath) var needle_path = null + + +func _on_value_updated(_value: int, value_percent: float) -> void: + get_node(needle_path).rotation.y = -( + deg2rad(min_angle) + + value_percent * deg2rad(max_angle - min_angle) + ) diff --git a/vehicles/pedal.gd b/vehicles/pedal.gd new file mode 100644 index 0000000..97c221c --- /dev/null +++ b/vehicles/pedal.gd @@ -0,0 +1,8 @@ +extends MeshInstance + +export(float) var min_angle = 0 +export(float) var max_angle = 45 + + +func _on_value_updated(value_percent: float) -> void: + rotation.x = -(deg2rad(min_angle) + value_percent * deg2rad(max_angle - min_angle)) diff --git a/vehicles/steering_controller.gd b/vehicles/steering_controller.gd new file mode 100644 index 0000000..4624a0c --- /dev/null +++ b/vehicles/steering_controller.gd @@ -0,0 +1,11 @@ +extends MeshInstance + +export(float) var max_steer_angle = 90 + + +func update_angle(steering_angle_percent: float) -> void: + rotation.z = deg2rad(max_steer_angle) * steering_angle_percent + + +func _on_steering_updated(_steering_angle: float, steering_angle_percent: float) -> void: + update_angle(steering_angle_percent) diff --git a/vehicles/vehicle.gd b/vehicles/vehicle.gd index 113901f..0632149 100644 --- a/vehicles/vehicle.gd +++ b/vehicles/vehicle.gd @@ -3,7 +3,11 @@ extends VehicleBody signal speed_updated(speed_kph, speed_percent) signal rpm_updated(rpm, rpm_percent) +signal throttle_updated(throttle_percent) +signal brake_updated(brake_percent) +signal clutch_updated(clutch_percent) signal gear_updated(gear) +signal steering_updated(steering_angle, steering_percent) export(float) var max_steer_angle = 25 export(float) var speed_steer_angle = 10 @@ -47,6 +51,11 @@ onready var flsmoke: TireSmoke = $fl_tire_smoke onready var rrsmoke: TireSmoke = $rr_tire_smoke onready var rlsmoke: TireSmoke = $rl_tire_smoke +onready var cockpit: Position3D = $cockpit +onready var hood: Position3D = $hood +onready var bumper: Position3D = $bumper +onready var static_follow: Position3D = $static_follow + onready var engine_sound_player: AudioStreamPlayer3D = $engine_sound_player onready var engine_sound_playback: AudioStreamPlayback = $engine_sound_player.get_stream_playback() @@ -66,6 +75,22 @@ func _ready(): engine_sound_player.play() +func get_cockpit_position() -> Node: + return cockpit + + +func get_hood_position() -> Node: + return hood + + +func get_bumper_position() -> Node: + return bumper + + +func get_static_follow_position() -> Node: + return static_follow + + func _integrate_forces(state: PhysicsDirectBodyState) -> void: if reset_transform != Transform.IDENTITY: state.linear_velocity = Vector3.ZERO @@ -184,6 +209,9 @@ func _physics_process(delta: float): var final_input = transmission_input * final_drive + emit_signal("throttle_updated", throttle) + emit_signal("brake_updated", brake_input) + emit_signal("clutch_updated", clutch_position) brake = brake_input * max_brake_force engine_force = throttle * final_input * max_engine_force @@ -210,6 +238,7 @@ func _physics_process(delta: float): 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) func _generate_engine_sound(rpm_factor):