Footsteps script...

Hi guys and girls…

Just thought I would post this for you, its a simple footsteps script I’ve been using for years works in all games I have developed… just make slight adjustments to the script to make the sound work perfectly…

So heres the script enjoy!!

using UnityEngine;
using System.Collections;

public class Footsteps : MonoBehaviour {

public AudioClip audioFootsteps;
private Vector3 prevPosition;
float minDistance = 2.4f;

void Start()
{
  prevPosition = transform.position;
}

void Update()
{
    if (Vector3.Distance(transform.position, prevPosition) > minDistance)
    {
        AudioSource.PlayClipAtPoint(audioFootsteps, transform.position);
        prevPosition = transform.position;
    }
}
}
3 Likes

thank you bro! hi from 2024 :smile:

There’s a Like button on every post so you don’t dredge up nine-year-old dead threads into everyone’s feed. It’s against the forum rules to bring up old threads unless you have vital updates to share.

This is a good start to a script (and surprisingly, not much broken in the years past). It does cause a whole invisible AudioSource to be created, where you could do better by pooling a set of footstep objects. Once you’re pooling objects, you can start looking at putting down decals or dust clouds at the same time.

Please don’t necro post. Use the like button in future.
Thread locked