Godot Version
4.7.stable
Question
So there’s this slime enemy that I’ve set up so that it should make a squelch sound when it jumps. The enemy’s scene also has an AudioStreamPlayer2D for this where it’s called like this.
func _on_timer_timeout() -> void:
if is_on_floor():
jump_ready=true
timer.start()
jump_start.play()
where the timer is how often it jumps and the actual jumping is done if the main _process function loop if the jump_ready bool is true but if I move the sound code to where the actual jump happens it still doesn’t play.
func _process(delta: float) -> void:
if global.running:
if not is_on_floor():
velocity.y += GRAVITY * delta
if !hit:
velocity.x = SPEED * direction
else:
velocity.x = 0
hit = false
if found:
destination=target.position
if jump_ready:
jump_start.play()
if frog.position.x>destination.x:
direction = -1
else:
direction = 1
jump_ready = false
velocity.y = JUMP_SPEED
I’m all the more confused as in the base scene for my game there are two AudioStreamPlayer2D’s that do work, one for the intro to the looping background track and the looping track. The preamble one is called in the _ready function(of the ui node’s script for some reason, idk)
func _ready() -> void:
music_start.play()
and the other uses signals of the first one ending and itself ending to loop itself.
func _on_music_start_finished() -> void:
main_music.play()
func _on_main_music_finished() -> void:
main_music.play()
all of this works fine and makes sense. They also have their bus set to their own music bus.
The enemy’s sound is set to play on an separate sfx bus. The audio file plays in the editor. I tried a whole bunch of different sound formats, I tried adding a sound listener to the player(I didn’t have one before but the music would still play despite them both being the 2d AudioStream variant).
It works with a regular AudioStreamPlayer which I actually found out when trying to make this post which is progress and could still work but I still don’t get why it isn’t working.
I also only added the AudioListener2D very recently and from my understanding that should have fixed things unless I did that wrong.
I’ve got an AudioListener2D in my player scene and the following in the player script
func _ready() -> void:
listener.make_current()
The whole project is up on my github if I haven’t explained things enough or you need more information(the enemy is referred to as frog(it’s a slime though) because I thought it was funny but fyi there’s that discrepancy).