Question
I am trying to make a footstep sound effect for my game, but the sound only plays when I stop moving, I can be sprinting, crouching, or idle and my sound effect plays but never when I am walking, my state machine is working fine because I put prints on each of the states and its working.
Code I have so far: (I don’t know how to work sounds in Godot)
if State == States.Walking:
Walking_Footsteps.play()
else:
Walking_Footsteps.stop()
I know its not much but that is all I know in terms of sounds in Godot lol
unlike with animators, .play() will re-start the sound. Try playing the sound when transitioning to Walking, and stopping when transitioning out of Walking.
func transition_state(new_state: States) -> void:
if new_state == State: # no change, ignore
return
# transitioning from
if State == States.Walking:
Walking_Footsteps.stop()
# transitioning to
if new_state == States.Walking:
Walking_Footsteps.play()
State = new_state