Browse Source

:tada: First implementation on car crash

DricomDragon 1 year ago
parent
commit
6969f4d3de

+ 2 - 0
godot/component/entity/vehicles/jeep/Jeep.tscn

@@ -20,6 +20,8 @@ collision_mask = 11
 mass = 400.0
 center_of_mass_mode = 1
 center_of_mass = Vector3(0, 0.06, 0)
+max_contacts_reported = 1
+contact_monitor = true
 script = ExtResource("1_fjw46")
 max_engine_force = 1842.0
 

+ 2 - 0
godot/component/entity/vehicles/plane/tiny_plane.tscn

@@ -18,6 +18,8 @@ collision_layer = 8
 collision_mask = 3
 input_ray_pickable = false
 mass = 750.0
+max_contacts_reported = 1
+contact_monitor = true
 script = ExtResource("1_tviov")
 
 [node name="TinyPlane" parent="." instance=ExtResource("2_60pln")]

+ 20 - 3
godot/component/entity/vehicles/seated_vehicle.gd

@@ -1,9 +1,15 @@
 class_name SeatedVehicle
 extends VehicleBody3D
 
+const CRASH_EFFECT: Resource = preload("res://effect/crash/crash.tscn")
+
 var _current_commander: LocalInput = null
 
 
+func _init() -> void:
+	body_shape_entered.connect(_on_body_shape_entered)
+
+
 ## Make the vehicle responds to driver commands
 func drive_with(commander: LocalInput) -> void:
 	commander.dir_changed.connect(_on_dir_changed)
@@ -17,16 +23,27 @@ func get_out() -> void:
 	_current_commander = null
 
 
-## Need to be overriden to return an available seat
+func _on_body_shape_entered(body_rid: RID, body: Node, body_shape_index: int, local_shape_index: int) -> void:
+	if body is Node3D:
+		_crash_on(body as Node3D)
+
+
+func _crash_on(body: Node3D) -> void:
+	var crash_effect: CrashEffect = CRASH_EFFECT.instantiate()
+	crash_effect.position = body.get_position()
+	get_parent_node_3d().add_child(crash_effect)
+
+
+## Need to be overridden to return an available seat
 func get_free_seat() -> Node3D:
 	return null
 
 
-## Need to be overriden to react to direction changed
+## Need to be overridden to react to direction changed
 func _on_dir_changed(dir: Vector2) -> void:
 	pass
 
 
-## Need to be overriden to react to main action
+## Need to be overridden to react to main action
 func _on_main_action(pressed: bool) -> void:
 	pass

+ 15 - 0
godot/effect/crash/crash.gd

@@ -0,0 +1,15 @@
+class_name CrashEffect
+extends Node3D
+
+
+func _init():
+	print("Crash init")
+
+
+func _ready():
+	print("Crash ready")
+
+
+func _on_noise_finished():
+	print("Crash end")
+	queue_free()

+ 12 - 0
godot/effect/crash/crash.tscn

@@ -0,0 +1,12 @@
+[gd_scene load_steps=3 format=3 uid="uid://c4hecxruavnfm"]
+
+[ext_resource type="Script" path="res://effect/crash/crash.gd" id="1_8bcl0"]
+[ext_resource type="Script" path="res://effect/crash/noise.gd" id="1_xh8ax"]
+
+[node name="Crash" type="Node3D"]
+script = ExtResource("1_8bcl0")
+
+[node name="Noise" type="AudioStreamPlayer3D" parent="."]
+script = ExtResource("1_xh8ax")
+
+[connection signal="finished" from="Noise" to="." method="_on_noise_finished"]

BIN
godot/effect/crash/crash.wav


+ 24 - 0
godot/effect/crash/crash.wav.import

@@ -0,0 +1,24 @@
+[remap]
+
+importer="wav"
+type="AudioStreamWAV"
+uid="uid://dgan1kd4awbv3"
+path="res://.godot/imported/crash.wav-6daf76efbf2c8fb4389d0abeac620c85.sample"
+
+[deps]
+
+source_file="res://effect/crash/crash.wav"
+dest_files=["res://.godot/imported/crash.wav-6daf76efbf2c8fb4389d0abeac620c85.sample"]
+
+[params]
+
+force/8_bit=false
+force/mono=false
+force/max_rate=false
+force/max_rate_hz=44100
+edit/trim=false
+edit/normalize=false
+edit/loop_mode=0
+edit/loop_begin=0
+edit/loop_end=-1
+compress/mode=0

BIN
godot/effect/crash/crash1.wav


+ 24 - 0
godot/effect/crash/crash1.wav.import

@@ -0,0 +1,24 @@
+[remap]
+
+importer="wav"
+type="AudioStreamWAV"
+uid="uid://bjdlevxm7vn3u"
+path="res://.godot/imported/crash1.wav-8f906101d7ae30a9e184dd64152ca3f1.sample"
+
+[deps]
+
+source_file="res://effect/crash/crash1.wav"
+dest_files=["res://.godot/imported/crash1.wav-8f906101d7ae30a9e184dd64152ca3f1.sample"]
+
+[params]
+
+force/8_bit=false
+force/mono=false
+force/max_rate=false
+force/max_rate_hz=44100
+edit/trim=false
+edit/normalize=false
+edit/loop_mode=0
+edit/loop_begin=0
+edit/loop_end=-1
+compress/mode=0

BIN
godot/effect/crash/crash2.wav


+ 24 - 0
godot/effect/crash/crash2.wav.import

@@ -0,0 +1,24 @@
+[remap]
+
+importer="wav"
+type="AudioStreamWAV"
+uid="uid://bsqcjj6n05ceq"
+path="res://.godot/imported/crash2.wav-7fc3491a1a4272856dcab6ae1880da19.sample"
+
+[deps]
+
+source_file="res://effect/crash/crash2.wav"
+dest_files=["res://.godot/imported/crash2.wav-7fc3491a1a4272856dcab6ae1880da19.sample"]
+
+[params]
+
+force/8_bit=false
+force/mono=false
+force/max_rate=false
+force/max_rate_hz=44100
+edit/trim=false
+edit/normalize=false
+edit/loop_mode=0
+edit/loop_begin=0
+edit/loop_end=-1
+compress/mode=0

BIN
godot/effect/crash/crash3.wav


+ 24 - 0
godot/effect/crash/crash3.wav.import

@@ -0,0 +1,24 @@
+[remap]
+
+importer="wav"
+type="AudioStreamWAV"
+uid="uid://edhbiwpf1g8q"
+path="res://.godot/imported/crash3.wav-7986dea14d5b51a587db39249271ceb1.sample"
+
+[deps]
+
+source_file="res://effect/crash/crash3.wav"
+dest_files=["res://.godot/imported/crash3.wav-7986dea14d5b51a587db39249271ceb1.sample"]
+
+[params]
+
+force/8_bit=false
+force/mono=false
+force/max_rate=false
+force/max_rate_hz=44100
+edit/trim=false
+edit/normalize=false
+edit/loop_mode=0
+edit/loop_begin=0
+edit/loop_end=-1
+compress/mode=0

+ 8 - 0
godot/effect/crash/noise.gd

@@ -0,0 +1,8 @@
+extends AudioStreamPlayer3D
+
+const crash_sound: Resource = preload("res://effect/crash/crash.wav")
+
+
+func _ready() -> void:
+	stream = crash_sound
+	play()