Hello! I’d like to make an footstep system for my NPC, it works simply like this:
Based on his walkspeed (and if he’s walking), it will play a sound per step.
If his walkspeed gets higher (He starts running), it will get a faster playbackspeed.
Is that possible to create? If so, how would I script that?
PS: I already tried doing it using Humanoid.MoveDirection.Magnitude.
moveDirection.Magnitude would be the speed they’re going at, e.g 0.5 = half their walkspeed
moveDirection * walkspeed = speed they’re walking at
playBackSpeed would be 1 for their normal walking speed, so divide by 16
so, just set the PlayBackSpeed to that
local function PlayStepSound()
local MoveDirection = Humanoid.MoveDirection.Magnitude
Step.Playing = MoveDirection > 0.5
Step.PlaybackSpeed = MoveDirection * humanoid.WalkSpeed / 16
end
I tried switching and it didn’t work, the NPC just kept walking without any sound, and before you ask or think on it, yes, the properties are not the problem.
I’m not sure if it’s the GetPropertyChangedSignal that is making it not work.
Have you tried messing with keyframe markers? You don’t have to mess around with trying to calculate speed. You just need to place markers on each step.
Its accurate to the step and “speeds up” whenever you run faster. You can change the pitch of the noise or add additional effects to make it more believable.
Just open your animation on a rig using animator editor.
Then, find the keyframe where the character begins to make a step, on that step, place a keyframe marker.
Do that for the consequent steps in the animation.
Once finished, export as usual and your animation should come with keyframe markers embedded.
In your local script or normal script or whatever script you’re doing it in, simply attach an event that checks the animation for a marker reached. If that specific marker is reached, play footstep sound.
TL:DR
Export animation with keyframe markers setup on each step.
Connect event and play sound whenever keyframe marker is reached.