Compare Distances

I am trying to figure out how to have a sound play and stay playing over and over again when a player is next to another object. Then I want the sound to stop when the player is a certain distance away from the object. I’ve tried using the Compare Distances condition but it only activates one time when it is in range. I need the sound to continue to play as long as the player is within the proximity of another object. I’ve tried using timers with no luck. Any ideas?

Maybe using the Raycast?

Was the music set to loop?

Pls show your compare distances condition!

I tried looping sound. No luck.

Try adding “trigger only once while true” condition from the advance option, i think this should fix this, but if still this is not fixed, instead of play sound action add play music action make sure loop is on again.

Trigger only once makes the sound play one time. You have to go out of range and back in for the sound to play again. This is not want I need. I want it to play over and over as long as the player is within the range of the enemy and then turn off when the player is away from the enemy. If I set the music or sound to loop, the sound will continue to play but overlap on top of the previous time it activates the sound. Hope that makes sense. I’m new to gdevelop but have made about 6 games using it. I used to use GameMaker. I wish gdevelop would just have a play music until done feature. The gdevelop timer stuff should have a way to activate a timer when I want it to activate. This would make this easier. But I am committed to gdevelop. Just need to figure out how to make certain things happen the way I thought the action was supposed to work.

I have it sort of working now. I think there is a bug in gdevelop. I used the Compare Distances condition and told it to invert. That means that when my player is outside the proximity of the enemy it should play my sound. But guess what…it plays the sound when it is inside the proximity of the enemy. It is like the Compare Distances condition works the opposite of how it should.

Ok Great but i think this might be the solution
In that event you have added a condition which say timer is NOT PAUSE and the below one, the action to this is that you play that sound and then you PAUSE that same timer, which then doesn’t match with conditions and therefore sound only plays once because the timer is no more NOT PAUSED, try removing that action! and also for the above event of this one, there is no need to add a action to unpause the timer when you reset it because its already playing…

Here is a cleaned up version of the code just in case someone else might need it. I eliminated the Compare Distances condition and just used the positions from my hidden objects to test how far away the player is from the enemy.

1 Like