Playing sound for a rolling ball

Regarding the rolling ball game template in UE, how would you play a sound for the ball rolling? Since it’s not an animation but physical simulation, you can’t use AnimNotify. What you’ve got is only the Hit event, which determines when the ball touches something. This event fires several times per second. Somehow you need to start playing the rolling sound, play it until the ball stops touching the surface (is there any event for it?) and you also have to make sure the same sound doesn’t start over and over with every Hit event fired, but starts over when finished, like a regular loop.

Even more advanced topic is how to determine when the ball lands, so it can play a landing sound once. Maybe the Normal Impulse argument of the Hit event could help?

I’m mainly stuck at the playing rolling sound in normal loops part. What’s the simplest solution?

1 Like

When the ball is rolling, play a roll sound cue (looping), increasing it’s pitch if it’s velocity increases.

On tick, check the previous and currect Z velocity. If there is a big change, that’s your fall. You can do that with a hit event on the ball if you desire to play the same sound on land or if it hits something.

Here is a relevant example of pitch going up with velocity: Turbo , Engine and Nitrous Sound Setup - YouTube

The trick with pitch sounds great. How do I prevent the sound playing over and over from beginning through? The Hit even fires several times per second when the ball is rolling, which means that if I start playing the rolling sound on Hit event, I have several tens of sounds playing simultaneously? Any idea?

Hmm, I am not familiar with the rolling ball project but I think you can either manually check the velocity of the ball or add a sphere collision component with locked rotation and check with that. You could also try the Overlap events.

Do once?
:slight_smile:

This seems to be a solution using sphere collison. The other two events are called on Tick.

&stc=1

&stc=1

At the end I used volume with speed, which I think fits this case better.

Thanks Zarkopafilis

I’ve just finished making a marble maze mini-game for my current project, and this is how I handled the sound for the marble rolling:

The audio file itself is just a 4-second looping sound of a marble rolling. Then I simply created a function using a Timer to check the velocity of the marble. As long as the velocity is higher than X (in my case 4), then I use a timeline to fade in the looping sound over 0.1 seconds. The curve for the timeline is just two points, 0,0 and .1,1 with a smooth curve. If the velocity is lower than X, I reverse the timeline to fade out the audio. I use the result of each to reset the DoOnce node so the audio doesn’t get updated constantly while moving.

And the Timer is set on Begin play. Ignore the first timer, that’s just how I update my controls.

The Gate is just there so I can disable the audio on the win condition and isn’t necessary. Also, the Bool is completely unnecessary too. I was originally planning to handle it differently.

3 Likes

@TorQueMoD Thanx for sharing this.
I have a question about the Marble Rolling node. I assume that this is an audio thing, though I can’t figure out which one it is? Can you drop in a screenshot or a note on which node this is? Note: I’m currently using Metasounds in my project. Thank you.
image

Oh, I thought it was a SoundBase variable, but in this case, I think it was actually an Audio Component added to the blueprint with auto-activate on. That way it’s always playing and you’re just using the code there to turn the volume up or down based on velocity.

Ahhh, gotcha. I wondered if it was something like that. Thanx for the quick response. :slight_smile:

How did you made sound play in loop? Play node just plays it once and then stops

Inside your sound u have a looping check

Select the wav node inside your cue and you’ll see a loop checkbox on the details in the left. Optionally you can set it on the imported wav file too, but it’s better to set it with sound cues.



Its strange but((( no such option. Could it be glitch? Im just droped wav into blueprint.

updated^
I clicked on wav asset in brouser and there are exist looping settings. Its better then nothing. Is there looping options somewhere else?

I must select node and loop option should be in details?


something wrong with my ue

It’s not your UE :stuck_out_tongue:
You need to set it inside the Cue file. Right click the imported audio and create sound cue. The select the Wave Player node and check the Looping bool.

1 Like