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?

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



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.


@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.

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: