Thanks for the answer, but unfortunately, the issue still persists. However, I think I figured out the issue.
Input.is_action_pressed("move_forward"):
is called inside physics process, that means that if I press "move forward"
, the game will check it every frame. I actually intended for that to be there, as I want to check the ground every frame to change sounds. Putting this inside _input(event)
caused some issues regarding the detection of new terrains
So, I think the issue is that the function is being executed every frame, which doesn't let the signal do its thing. The same sound just plays over and over again until I enter an area that enables the footsteps or when I press "move_forward" again.
I tried adding a boolean to execute the function only once, but it doesn't seem to work
var Sample1
var Sample2
var Sample3
var Sample4
onready var execute_function: bool
func _ready():
floor_raycast.enabled = true
func Footsteps4(sample1, sample2, sample3, sample4): #Footsteps function for 4 samples
if execute_function == true:
var random_number = rng.randi_range(0, 3)
match str(random_number): #Match the result of the rng as a string (text) - the result must be stored as a variable
"0":
if AudioPlayer.is_playing() == false: #So it doesn't change stream mid playing
AudioPlayer.stream = sample1
Sample1 = sample1 #Storing the currently used sound as a variable
"1":
if AudioPlayer.is_playing() == false: #So it doesn't change stream mid playing
AudioPlayer.stream = sample2
Sample2 = sample2
"2":
if AudioPlayer.is_playing() == false: #So it doesn't change stream mid playing
AudioPlayer.stream = sample3
Sample3 = sample3
"3":
if AudioPlayer.is_playing() == false: #So it doesn't change stream mid playing
AudioPlayer.stream = sample4
Sample4 = sample4
if AudioPlayer.is_playing() == false: #This is to prevent the audios from playing every frame
AudioPlayer.play()
execute_function = false
func _physics_process(delta):
var obj = floor_raycast.get_collider()
if floor_raycast.is_colliding() == true:
if Input.is_action_pressed("move_forward"):
execute_function = true
Footsteps4(PWalking1, Pwalking2, Pwalking3, Pwalking4)
elif floor_raycast.is_colliding() == false:
AudioPlayer.stop()
if Input.is_action_just_released("move_forward"):
AudioPlayer.stop()
func _on_Footsteps_finished():
Footsteps4(Sample1, Sample2, Sample3, Sample4) # Runs the function again with the same sounds so the random number changes`
Any help would be appreciated