How do i make so my script detects when my player is moving? Please help me! I have tried everything…
using UnityEngine;
using System.Collections;
public class Knight : MonoBehaviour
{
void DetectPlayerMoving()
{
//insert code here
}
Erm… is the Knight script attached to a GameObject with a rigidbody? If so all you need to do is get the rigidbody with GetComponent() in Start and store it in a global variable, then check in FixedUpdate if the magnitude of it’s velocity is larger than some threshold.
If it only moves ones then You could have a moving variable that you enable in your movement code. Then you could set it to false in update if it isn’t already code:
bool moving = false;
// Add this to movement code:
moving = true
void Update() {
if(moving == true){
moving = false;
}
}
Hope this helps!