Add cockpit to buggy

pull/1/head
Ensar Sarajčić 2022-01-19 14:35:14 +01:00
parent 15d2c83ffc
commit 2e44a97f63
14 changed files with 79 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,8 +1,12 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=17 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=6]
[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 +62,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( 6 )
[node name="clutch_pedal" parent="chassis/cockpit" index="1"]
script = ExtResource( 7 )
[node name="gas_pedal" parent="chassis/cockpit" index="2"]
script = ExtResource( 6 )
[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
@ -141,7 +172,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.950753, -0.0380455, -1.41438
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.36101, 0 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.32501, -0.0235026 )
[node name="hood" type="Position3D" parent="." index="14"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31056, 0.894584 )
@ -151,3 +182,10 @@ 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"]

12
vehicles/meter.gd 100644
View File

@ -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)
)

View File

@ -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))

View File

@ -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)

View File

@ -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
@ -205,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
@ -231,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):