Is it possible to tie an audio clip's playback to a GameObject's position?

Basically, I have a door the player can push open and I want to play a squeal noise while the door is moving. Since the player can push it open a bit, then stop, then slam it open all the way just doing Squeak.Play won’t work. I’m trying to set it up to play through an audio clip based on how open the door is.

If I may recommend a different Approach: Play a Clip based on the door’s velocity, and and remember that it will only slam if you are closing it.

-ch

How would that handle the fast > stop > slow case? The door’s variable speed prevents me from just getting the velocity and playing a clip based on that.

You can poll the velocity and change the clip as needed. You can even change the pitch of the clip (a slower velocity might have a lower pitched squeal for example).

1 Like

just what I was gonna suggest, I wouldn’t change the clip itself though, just the pitch.

when you see the door is starting to move (IE “velocity” != 0 || lastPos != pos) hit play on it, change the pitch so that lower speed = lower pitch and vise versa, if you see there’s no movement from last frame (IE “velocity” == 0 || lastPos == pos) stop the sound, if you get into a specific place, like the door frame or the door stopper, see what the “velocity” is when hitting the area and play a door slam / some kind of knock for the stopper / what ever is appropriate for the object being hit.

edit: the only problem I see here i getting a screeching sound that’s looping good, I always end up doing this kind of stuff myself…
just last night I had to make a looping “wind” noise (for a ballistic projectile to “whoooosh”), spent like an hour blowing on the mic until I saw the option to generate brownian noise that fits perfectly with a hint of reverb and a lowpass filter.

1 Like