Skip to content

Commit

Permalink
Audio improvements, fixed angular forces (no more glitching out!)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyIF committed Dec 23, 2024
1 parent c2bc7ea commit b9c86c7
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 16 deletions.
1 change: 1 addition & 0 deletions addons/aacc/scenes/hit_sound.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ stream_2/stream = ExtResource("3_0isay")
[node name="HitSound" type="AudioStreamPlayer3D"]
stream = SubResource("AudioStreamRandomizer_leb08")
unit_size = 5.0
max_db = 0.0
autoplay = true
bus = &"SFX"
doppler_tracking = 2
Expand Down
1 change: 1 addition & 0 deletions addons/aacc/scenes/land_sound.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[node name="LandSound" type="AudioStreamPlayer3D"]
stream = ExtResource("1_hrrbl")
unit_size = 5.0
max_db = 0.0
autoplay = true
bus = &"SFX"
doppler_tracking = 2
Expand Down
19 changes: 19 additions & 0 deletions addons/aacc/scripts/audio/car_brake_squeal_sound.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## TODO: documentation
class_name CarBrakeSquealSound extends AudioStreamPlayer3D

@onready var car: Car = get_node("..")

var smoothed_brake_amount: SmoothedFloat = SmoothedFloat.new(0.0, 8.0, 4.0)

func _physics_process(delta: float) -> void:
var target_value: float = (car.input_forward if car.is_reversing() else car.input_backward) * car.ground_coefficient
# TODO: account velocity too
smoothed_brake_amount.advance_to(target_value, delta)
volume_db = linear_to_db(lerp(0.0, 1.0, smoothed_brake_amount.get_current_value()))

if is_inf(volume_db):
volume_db = -80.0
if volume_db >= -60.0 and not playing:
play(randf_range(0.0, stream.get_length()))
elif volume_db < -60.0 and playing:
stop()
1 change: 1 addition & 0 deletions addons/aacc/scripts/audio/car_brake_squeal_sound.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://t5im4xcigfjb
10 changes: 5 additions & 5 deletions addons/aacc/scripts/audio/car_tire_screech_sound.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## TODO: documentation
class_name CarTireScreechSound extends AudioStreamPlayer3D
@export var pitch_range: Vector2 = Vector2(0.5, 1.0)

@onready var car: Car = get_node("..")

func _physics_process(_delta: float) -> void:

pitch_scale = lerp(0.5, 1.25, car.burnout_amount)

pitch_scale = lerp(pitch_range.x, pitch_range.y, car.burnout_amount)
volume_db = linear_to_db(car.burnout_amount)

if is_inf(volume_db):
volume_db = -80.0
if volume_db > -60.0 and not playing:
if volume_db >= -60.0 and not playing:
play(randf_range(0.0, stream.get_length()))
elif volume_db <= -60.0 and playing:
elif volume_db < -60.0 and playing:
stop()
4 changes: 2 additions & 2 deletions addons/aacc/scripts/car.gd
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func update_burnout_amount():
burnout_revs = linear_velocity.length() / 10.0
if abs(local_linear_velocity.z) < 0.25:
burnout_revs = revs.get_current_value()

burnout_amount = clamp(burnout_colliding * (burnout_velocity + burnout_revs), 0.0, 1.0)
#endregion

Expand Down Expand Up @@ -439,7 +439,7 @@ func _physics_process(delta: float) -> void:

var desired_steer_force: Vector3 = Vector3.UP * get_steer_force()
var sum_of_angular_forces: Vector3 = convert_angular_force(desired_steer_force, delta)
apply_torque(sum_of_angular_forces * average_wheel_collision_normal * ground_coefficient / delta)
apply_torque(sum_of_angular_forces.project(average_wheel_collision_normal) * ground_coefficient / delta)
else:
var desired_air_stabilization_force: Vector3 = get_air_stabilization_force() * delta

Expand Down
6 changes: 4 additions & 2 deletions addons/aacc/scripts/car_wheel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class_name CarWheel extends Node3D
##
## AACC's wheels currently use 2 raycasts for the wheels.
@export var wheel_width: float = 0.3
# TODO: document
@export_flags_3d_physics var collision_mask: int = 1

@export_group("Suspension")
## The maximum length of the suspension.
Expand Down Expand Up @@ -90,15 +92,15 @@ func configure_raycasts() -> void:
raycast_instance_1.enabled = true
raycast_instance_1.hit_from_inside = false
raycast_instance_1.hit_back_faces = false
raycast_instance_1.collision_mask = 1
raycast_instance_1.collision_mask = collision_mask
raycast_instance_1.process_physics_priority = -1000
raycast_instance_1.position = Vector3.RIGHT * wheel_width

raycast_instance_2.target_position = (Vector3.DOWN * (wheel_radius + suspension_length))
raycast_instance_2.enabled = true
raycast_instance_2.hit_from_inside = false
raycast_instance_2.hit_back_faces = false
raycast_instance_2.collision_mask = 1
raycast_instance_1.collision_mask = collision_mask
raycast_instance_2.process_physics_priority = -1000

func set_raycast_values() -> void:
Expand Down
8 changes: 6 additions & 2 deletions addons/aacc/scripts/hit_reaction.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extends Node3D
@onready var scratch_sound: AudioStreamPlayer3D = get_node("ScratchSound")

var sparks_control: int = 0
var smooth_scratch_amount: SmoothedFloat = SmoothedFloat.new(0.0, 50.0, 5.0)

func play_hit_sound(_body: Node) -> void:
var state: PhysicsDirectBodyState3D = PhysicsServer3D.body_get_direct_state(car_rid)
Expand Down Expand Up @@ -68,11 +69,14 @@ func _physics_process(delta: float) -> void:
total_scratch_amount = clamp(total_scratch_amount, 0.0, 1.0)
if not scratch_sound.playing:
scratch_sound.play(randf_range(0.0, scratch_sound.stream.get_length()))
scratch_sound.volume_db = linear_to_db(total_scratch_amount)
scratch_sound.pitch_scale = lerp(0.5, 1.0, clamp(total_scratch_amount, 0.0, 1.0))
else:
scratch_sound.stop()
sparks_control = 0

smooth_scratch_amount.advance_to(total_scratch_amount, delta)
scratch_sound.volume_db = linear_to_db(smooth_scratch_amount.get_current_value())
if scratch_sound.volume_db < -60.0: # TODO: get from project settings
scratch_sound.stop()

# TODO: use delta
sparks_control += 1
Expand Down
3 changes: 3 additions & 0 deletions addons/aacc/shaders/shadow_decal_shader.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ void fragment() {
#if CURRENT_RENDERER == RENDERER_MOBILE
// Similar story to Compatibility renderer, except that this value is
// fixed and doesn't change depending on environment settings.
//
// Keep in mind that the rendering breaks for some reason when MSAA is
// enabled. Try using FXAA instead.
ALBEDO *= 2.0;
#endif
}
3 changes: 2 additions & 1 deletion addons/aacc/sounds/attribution.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
tire_screech.ogg: screeching tyres / tires by fractanimal -- https://freesound.org/s/614627/ -- License: Creative Commons 0
tire_screech.ogg: Chrysler LHS tire squeal 04 (04-25-2009).wav by audible-edge -- https://freesound.org/s/71739/ -- License: Creative Commons 0
collision_1.ogg: Collision 1 by JustInvoke -- https://freesound.org/s/446126/ -- License: Attribution 4.0
collision_3.ogg: Collision 2 by JustInvoke -- https://freesound.org/s/446125/ -- License: Attribution 4.0
collision_3.ogg: Collision 3 by JustInvoke -- https://freesound.org/s/446132/ -- License: Attribution 4.0
scratch.ogg: metal plate scratch by Ridderick -- https://freesound.org/s/707639/ -- License: Creative Commons 0
landing.ogg: Car Land/Hit by JustInvoke -- https://freesound.org/s/446135/ -- License: Attribution 4.0
brake_squeal.ogg: Car Brakes sqeak screech squeal stop.wav by WavJunction.com -- https://freesound.org/s/456764/ -- License: Creative Commons 0

Engine sounds created with https://github.com/DasEtwas/enginesound from on example .esc files
Binary file added addons/aacc/sounds/brake_squeal.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions addons/aacc/sounds/brake_squeal.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://cun1ch44lb6ma"
path="res://.godot/imported/brake_squeal.ogg-6c76d6ac2bcb276b35854e6d1b0198a0.oggvorbisstr"

[deps]

source_file="res://addons/aacc/sounds/brake_squeal.ogg"
dest_files=["res://.godot/imported/brake_squeal.ogg-6c76d6ac2bcb276b35854e6d1b0198a0.oggvorbisstr"]

[params]

loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4
Binary file modified addons/aacc/sounds/tire_screech.ogg
Binary file not shown.
9 changes: 5 additions & 4 deletions demo_assets/car_scenes/taxi.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,31 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 4)
[node name="CollisionBody" type="CollisionShape3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 2.18557e-09, 0.15, 0.025)
shape = SubResource("ConvexPolygonShape3D_8m1l8")
debug_color = Color(0, 0.6, 0.7, 0.42)

[node name="CollisionWheelBL" type="CollisionShape3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.3, 0.3, 0.76)
shape = SubResource("ConvexPolygonShape3D_l3td7")
debug_color = Color(0, 0.6, 0.7, 0.42)

[node name="CollisionWheelBR" type="CollisionShape3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.3, 0.3, 0.76)
shape = SubResource("ConvexPolygonShape3D_yb0ap")
debug_color = Color(0, 0.6, 0.7, 0.42)

[node name="CollisionWheelFL" type="CollisionShape3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.3, 0.3, -0.76)
shape = SubResource("ConvexPolygonShape3D_rxdha")
debug_color = Color(0, 0.6, 0.7, 0.42)

[node name="CollisionWheelFR" type="CollisionShape3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.3, 0.3, -0.76)
shape = SubResource("ConvexPolygonShape3D_s6wnr")
debug_color = Color(0, 0.6, 0.7, 0.42)

[node name="WheelBL" type="Node3D" parent="." node_paths=PackedStringArray("visual_node", "skid_trail", "burnout_particles")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.3, 0.3, 0.76)
script = ExtResource("3_gy57t")
buffer_radius = 0.05
wheel_width = 0.2
suspension_spring = 15000.0
suspension_damper = 1500.0
Expand All @@ -343,7 +347,6 @@ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0,
[node name="WheelBR" type="Node3D" parent="." node_paths=PackedStringArray("visual_node", "skid_trail", "burnout_particles")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.3, 0.3, 0.76)
script = ExtResource("3_gy57t")
buffer_radius = 0.05
wheel_width = 0.2
suspension_spring = 15000.0
suspension_damper = 1500.0
Expand All @@ -360,7 +363,6 @@ block_wheelspin = true
[node name="WheelFL" type="Node3D" parent="." node_paths=PackedStringArray("visual_node", "skid_trail", "burnout_particles")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.3, 0.3, -0.76)
script = ExtResource("3_gy57t")
buffer_radius = 0.05
wheel_width = 0.2
suspension_spring = 15000.0
suspension_damper = 1500.0
Expand All @@ -377,7 +379,6 @@ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0,
[node name="WheelFR" type="Node3D" parent="." node_paths=PackedStringArray("visual_node", "skid_trail", "burnout_particles")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.3, 0.3, -0.76)
script = ExtResource("3_gy57t")
buffer_radius = 0.05
wheel_width = 0.2
suspension_spring = 15000.0
suspension_damper = 1500.0
Expand Down

0 comments on commit b9c86c7

Please sign in to comment.