Tweak engine sounds

soundtrack
Ensar Sarajčić 2021-11-13 12:44:07 +01:00
parent 07a318c327
commit 6281358f47
3 changed files with 24 additions and 7 deletions

View File

@ -1,10 +1,13 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://vehicles/buggy.gd" type="Script" id=1]
[ext_resource path="res://assets/beetlecar.glb" type="PackedScene" id=2]
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0, 0 ), 0.0, 1.32264, 0, 1, Vector2( 0.481132, 0.636364 ), 1.32264, 0.0, 1, 0, Vector2( 0.877358, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
_data = [ Vector2( 0, 0 ), 0.0, 2.58337, 0, 1, Vector2( 0.221698, 0.572727 ), 2.58337, 0.0, 1, 0, Vector2( 0.830189, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="Curve" id=4]
_data = [ Vector2( 0, 0.492045 ), 0.0, 0.0, 0, 0, Vector2( 0.15566, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.212264, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.29717, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.410377, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.481132, 0.701136 ), 0.0, 0.0, 0, 0, Vector2( 0.566038, 0.282955 ), 0.0, 0.0, 0, 0, Vector2( 0.589623, 0.6375 ), 0.0, 0.0, 0, 0, Vector2( 0.660377, 0.373864 ), 0.0, 0.0, 0, 0, Vector2( 0.669811, 0.5375 ), 0.0, 0.0, 0, 0, Vector2( 0.764151, 0.0284091 ), 0.0, 0.0, 0, 0, Vector2( 0.811321, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.938679, 0 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 0.417676, 0.42291, 1.58775 )
@ -15,10 +18,12 @@ mix_rate = 5500.0
[node name="beetlecar" instance=ExtResource( 2 )]
mass = 140.0
script = ExtResource( 1 )
BASE_ENGINE_PITCH = 0.2
gear_ratios = [ 2.24, 2.0, 1.89, 1.67, 1.44, 1.23 ]
final_drive = 5.6
max_rpm = 8000.0
power_curve = SubResource( 3 )
sound_curve = SubResource( 4 )
[node name="rear_right" parent="." index="0"]
use_as_traction = true

View File

@ -14,6 +14,7 @@ export (float) var MAX_ENGINE_FORCE = 85.0
export (float) var MAX_BRAKE_FORCE = 50.0
export (float) var THROTTLE_POWER = 6000.0
export (float) var MAX_RPM_LOSS_PS = 3000.0
export (float) var BASE_ENGINE_PITCH = 0.5
export (Array) var gear_ratios = [ 3.4, 2.5, 2.0, 1.5, 1.25 ]
export (float) var reverse_ratio = -3
@ -22,6 +23,7 @@ export (float) var max_rpm = 3500
export (float) var min_rpm = 900
export (float) var gear_switch_time = 0.2
export (Curve) var power_curve = null
export (Curve) var sound_curve = null
var clutch_position: float = 0.0
var rpm = 0
@ -96,7 +98,7 @@ func _physics_process(delta: float):
else:
rpm = _lerp_rpm(rpm, min_rpm, delta, delta)
if _has_traction():
rpm += throttle * delta * clutch_position * THROTTLE_POWER
rpm += throttle * delta * (max(clutch_position, 1 if gear == 0 else 0)) * THROTTLE_POWER
else:
rpm += throttle * delta * THROTTLE_POWER
rpm = clamp(rpm, 0, max_rpm)
@ -134,10 +136,15 @@ func _physics_process(delta: float):
steering = steering_input * lerp(max_steer_angle_rad, speed_steer_angle_rad, steer_speed_factor)
func _generate_engine_sound(rpm_factor):
engine_sound_player.pitch_scale = 0.5 + rpm_factor
engine_sound_player.pitch_scale = BASE_ENGINE_PITCH + rpm_factor
var to_fill = engine_sound_playback.get_frames_available()
var factor = rpm_factor
if to_fill <= 0:
return
var fill_segment = 1.0 / to_fill
var fill_percent = 0.0
while to_fill > 0:
engine_sound_playback.push_frame(Vector2(1.0, 1.0) * factor)
factor += cos(factor) * sin(factor) * (1 + to_fill % 2)
factor += cos(factor) * sin(factor) * (1 + to_fill % 2) * (sound_curve.interpolate_baked(fill_percent) * 2 - 0.5)
to_fill -= 1
fill_percent += fill_segment

View File

@ -1,10 +1,13 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://assets/basic_buggy.glb" type="PackedScene" id=1]
[ext_resource path="res://vehicles/buggy.gd" type="Script" id=3]
[sub_resource type="Curve" id=2]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.259434, 0.463636 ), 0.0, 0.0, 0, 0, Vector2( 0.59434, 0.872727 ), 0.0, 0.0, 0, 0, Vector2( 0.900943, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.0660377, 0.243255 ), 0.0, 0.0, 0, 0, Vector2( 0.240566, 0.315982 ), 0.0, 0.0, 0, 0, Vector2( 0.429245, 0.925073 ), 0.0, 0.0, 0, 0, Vector2( 0.900943, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="Curve" id=4]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.0849057, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.15566, 0.746591 ), 0.0, 0.0, 0, 0, Vector2( 0.349057, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.382075, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.400943, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.438679, 0 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 0.521885, 0.334919, 1.78849 )
@ -15,7 +18,9 @@ mix_rate = 5500.0
[node name="buggy" instance=ExtResource( 1 )]
mass = 150.0
script = ExtResource( 3 )
BASE_ENGINE_PITCH = 0.95
power_curve = SubResource( 2 )
sound_curve = SubResource( 4 )
[node name="front_left" parent="." index="1"]
use_as_traction = true