How to loop a sound when using a single line trace?

Hello

I am trying to create a blueprint in which a single line trace (raycast) , Upon hitting an object (That has a certain type associated with it, such as floor, wall, object etc) will play a sound that then loops on an interval. Said interval will change depending on the distance from the player to the object.

Basically a parking sensor. (The idea is the project is to help to see if you navigate a 3D Space with just sound, using a variation of beeps and delays)
So a sound needs to play, then have a delay before play the sound again, and then loops this. The delay needs to be able to change with it’s distance, so it can’t be something done in just the sound. But I have two issues.

  1. I do not know how to reset the delay, So if I look at a wall for example, and then look back at it again, the delay is still present and stops the sound from playing and starting the loop as new. This also needs to be cleared if looking at a new object that would play a different sound.
  2. Because of the issue above, I have no clue on how to properly calculate the distance of the raycast and how it would affect the delay, to make the sound play faster or slower depending on how close or far the player is.

I have been stuck on this problem for a while now with what seems like it should be a simple blueprint. I don’t know if it’s something to do with delays and needing to use a different system or I am missing a big part of what I should be doing.

So far I have tried using gates and do once and function timers and clears. The gates almost work but I cannot get the desired effect properly. The function timers should work but they play constantly while looking at the object, but then play on the loop when looking away.

Any help would be appreciated (And if you feel willing, Any help or direction on how to calculate the distance of the raycast and for it to change said intervals of the sound would be great)

My code has a few different attempts on it, If it’s too messy to understand I can take more screenshots.

Sorry this is long winded and might be a complicated issue, I will explain more and provide more details as needed.

Thanks

Connected to EventTick. Currently play 10 sounds at distance 1 meter, 1 sound at 10 meters etc. If you want change it, just enter another value instead 1000.