How to play a sound when my AI is near the Player

Something like this ( untested ):

I’m assuming there’s only one enemy, at the moment ( and the heart sound is looping ).

So I am very new to using Unreal Engine and might not understand certain answers to what I imagine is an easy question so bare with me

I’m creating a game and wish for a sound effect to play for the player when my AI is nearby (A heart beat to be specific) I wish the sound to play in the characters ear and not something like a foot step in the distance.

If there’s an added way of controlling the volume or speed as the AI gets closer, that would be perfect, but just a simple Play sound when within this radius and stop playing a sound when they leave would be greatly appreciated!

Create a sound cue from your heartbeat sound like below. Don’t forget to set the parameter name.

In your CharacterBP, add an Audio component and set it’s “Sound” to the heartbeat sound cue you just created.

Do this in your CharacterBP:

You might want to use a less frequent the code instead of Event Tick, a timer or a timeline maybe.

This is just one solution. A better way to do it maybe to setup a Collision sphere around the character and check for collisions against AIPawns. In anycase, this is how you modify a sound’s volume(or pitch) at runtime.

Edit: The sound you use in your sound cue should be set to loop(ClockworkOcean thx for reminding)

In range A and B should be the other way around or the volume would increase as the distance grows.

Yes! - like I say, untested :wink: