Footsteps System - NPC

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.

humanoid.MoveDirection should be working, have you tried printing it?

I’m using it for my system, and it does work
image

Yes, I already tried printing. I have an line just for that.
image

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.

image

I’m not sure if it’s the GetPropertyChangedSignal that is making it not work.

I don’t think GetPropertyChangedSignal fires with MoveDirection changes, because it changes so often firing it would be bad for performance.

Try connecting to .Running instead

1 Like

Switched once again, nothing happened. I have my doubts on Step.Playing = MoveDirection > 0.5.

PS: Not even switching to Step:Play() makes it 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.

1 Like

I have no idea how to mess with KeyframeMarker.

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.

3 Likes

Thank you very much! That really helped me right now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.