How to detect player movement efficiently?

I’m trying to play a sound while the player is moving so i came up with this code:

if (step.isPlaying && rb.velocity.magnitude < 0.2) {
            step.Pause ();
        } else if (!step.isPlaying && rb.velocity.magnitude >= 0.2) {
            step.UnPause();
        }

But since i’m using transform.Translate to move the character i don’t think rb.velocity.magnitude works that great and it counts as movement if the player rotates, So i tried using rb.AddForce() to move the player but as you can probably tell that didn’t work out too great for me. So whats the best way to get player movement for this situation.

have a variable stored somewhere like “Vector3 previousPosition”
then have “Vector3 velocity = transform.position - previousPosition” (not sure if you need to multiply by Time.deltaTime)

Now just use that velocity instead of the rigidbody one

then remember to set previousPosition = transform.position after you are done using the velocity for that frame

Are you animating your player?

In that case, you could add animation events at about where their feet hits the ground, and play one shot of the step sound on that event.

Thanks this worked.