74 lines
3.0 KiB
GDScript
74 lines
3.0 KiB
GDScript
extends RayCast3D
|
|
|
|
@onready var player: CharacterBody3D = $".."
|
|
@onready var audio_hard_floor: AudioStreamPlayer3D = $Audio/AudioHardFloor
|
|
@onready var audio_snow: AudioStreamPlayer3D = $Audio/AudioSnow
|
|
@onready var audio_floor: AudioStreamPlayer3D = $Audio/AudioFloor
|
|
|
|
var collider
|
|
var audio_path
|
|
var get_pitch
|
|
##Using floor name aquire the correct pitch setting based on if player is running or not
|
|
@export var pitch = {"wood_floor": {false: 1, true: 2}, "snow_floor": {false: 0.66, true: 1.33}, "grass_floor": {false: 1, true: 2}}
|
|
|
|
## Play footstep sounds while walking and running
|
|
## TODO Add audio and speed while crouching
|
|
func _physics_process(_delta):
|
|
|
|
##If the player is moving and the floor ray is colliding with a floor
|
|
##Using get_collider() not null as it can account for objects queue freeing
|
|
if get_collider() != null and (player.velocity.x != 0 or player.velocity.z != 0):
|
|
collider = get_collider()
|
|
if collider.is_in_group("wood_floor"):
|
|
|
|
##Set the pitch
|
|
get_pitch = pitch["wood_floor"][player.switch_state_run] * player.con_mod
|
|
audio_floor.pitch_scale = randf_range(get_pitch - 0.2, get_pitch + 0.2)
|
|
|
|
##Load audio if not already playing or correct audio
|
|
if audio_floor.stream == null or audio_floor.stream.resource_path.get_file() != "565716__ralphwhitehead__footsteps-walking-on-wooden-floor-medium-pace.wav":
|
|
audio_floor.stream = load("res://assets/SFX/565716__ralphwhitehead__footsteps-walking-on-wooden-floor-medium-pace.wav")
|
|
#print(audio_floor.stream.resource_path)
|
|
|
|
## Play the audio
|
|
if !audio_floor.is_playing():
|
|
audio_floor.play()
|
|
|
|
elif collider.is_in_group("snow_floor"):
|
|
|
|
##Set the pitch
|
|
##TODO Fix something so snow walking sound effect does not have weird noise caused by pitch shifting
|
|
get_pitch = pitch["snow_floor"][player.switch_state_run] * player.con_mod
|
|
audio_floor.pitch_scale = randf_range(get_pitch - 0.05, get_pitch + 0.05)
|
|
|
|
if audio_floor.stream == null or audio_floor.stream.resource_path.get_file() != "421022__inspectorj__running-snow-a.wav":
|
|
audio_floor.stream = load("res://assets/SFX/421022__inspectorj__running-snow-a.wav")
|
|
#print(audio_floor.stream.resource_path)
|
|
|
|
## Play the audio
|
|
if !audio_floor.is_playing():
|
|
audio_floor.play()
|
|
|
|
elif collider.is_in_group("grass_floor"):
|
|
|
|
##Set the pitch
|
|
##TODO Fix something so snow walking sound effect does not have weird noise caused by pitch shifting
|
|
get_pitch = pitch["grass_floor"][player.switch_state_run] * player.con_mod
|
|
audio_floor.pitch_scale = randf_range(get_pitch - 0.2, get_pitch + 0.2)
|
|
|
|
if audio_floor.stream == null or audio_floor.stream.resource_path.get_file() != "389625__silentstrikez__footsteps_grass_1.wav":
|
|
audio_floor.stream = load("res://assets/SFX/389625__silentstrikez__footsteps_grass_1.wav")
|
|
#print(audio_floor.stream.resource_path)
|
|
|
|
## Play the audio
|
|
if !audio_floor.is_playing():
|
|
audio_floor.play()
|
|
|
|
##No collider with sound detected
|
|
else:
|
|
pass
|
|
|
|
## Stop playing foot sounds
|
|
else:
|
|
audio_floor.stop()
|