Change Animation Speed Based on Sound Volume

I don’t know how I would go about doing this, but I have an NPC playing a guitar with an animation. There is a sound playing, and I want to somewhat sync the animation with the sound so if the sound is quiet, he strums the guitar less. Any ideas?

2 Likes

i believe the two things you will want to look at is the PlaybackLoudness of a Sound object (link to PlaybackLoudness), and the AdjustSpeed() method on an AnimationTrack object (link to AdjustSpeed).

if you need more help, let me know I can try to provide some code examples, but this should be a good start for you to try on your own.

edit: typos

2 Likes

Thank you so much! This is the script I made.

local Animation = script.Parent.Hum:LoadAnimation(script.Animation)
Animation:Play()

local Sound = script.Parent.Head.Song

while wait(.1) do
	if Sound.PlaybackLoudness > 100 then
		Animation:AdjustSpeed(1)
	elseif Sound.PlaybackLoudness <= 0 then
		Animation:AdjustSpeed(.1)
	else
		Animation:AdjustSpeed(Sound.PlaybackLoudness / 100)
	end
end
1 Like

looks good to me

you’re very welcome :grin:

1 Like