Commit 64d16f00 authored by Andrew Van Buren's avatar Andrew Van Buren

Fixed footstep glitch

parent ffeb0fff
...@@ -19,8 +19,8 @@ public class HeroMobility : MonoBehaviour { ...@@ -19,8 +19,8 @@ public class HeroMobility : MonoBehaviour {
public AudioClip[] grassFootsteps; public AudioClip[] grassFootsteps;
public AudioClip[] waterFootsteps; public AudioClip[] waterFootsteps;
public bool canMove = true; public bool canMove = true;
void Start () { void Start () {
playerRB = GetComponent<Rigidbody2D> (); playerRB = GetComponent<Rigidbody2D> ();
...@@ -35,14 +35,14 @@ public class HeroMobility : MonoBehaviour { ...@@ -35,14 +35,14 @@ public class HeroMobility : MonoBehaviour {
playerMove (input); playerMove (input);
if(deltaPos.magnitude > 0.001f && Time.time > lastFootstep) { if(deltaPos.magnitude > 0.001f && Time.time > lastFootstep) {
lastFootstep += footStepDelay; lastFootstep = Time.time + footStepDelay;
Footstep(); Footstep();
} }
} }
void playerMove (Vector2 input){ void playerMove (Vector2 input){
//Controls hero movement in all 8 directions //Controls hero movement in all 8 directions
if(canMove) if(canMove)
playerRB.MovePosition((Vector2)transform.position + input.normalized*playerSpeed); playerRB.MovePosition((Vector2)transform.position + input.normalized*playerSpeed);
deltaPos = playerRB.position - lastPos; deltaPos = playerRB.position - lastPos;
lastPos = playerRB.position; lastPos = playerRB.position;
...@@ -60,4 +60,4 @@ public class HeroMobility : MonoBehaviour { ...@@ -60,4 +60,4 @@ public class HeroMobility : MonoBehaviour {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment