Sound effect only playing after I let go of the move key

Godot Version:
4.3

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.

1 Like

How would I go about doing that in code???

When changing states, use .play() and .stop()

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

tysm, helped alot

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.