How to detect is my player moving (2d game)

Yeah, i have tried everything. Please help me :frowning:

using UnityEngine;
using System.Collections;

public class Knight : MonoBehaviour
{
  
    void DetectPlayerMoving()
    {
        //insert code here
    }
}

Well, you haven’t tried everything. :slight_smile:

If this is the only script in your game so far, and if you aren’t using physics (which would be wise, especially for a beginner), then you can fill in line 9 as “return false;” because your object won’t ever be moving.

Excluding physics, objects in Unity only move when some code tells them to. So, probably the best solution is to find whatever code is making the player move, and do whatever you’re trying to do there.

Another alternative is to watch the .transform.position of the player, and when that changes, conclude that the player is moving. This approach is a little indirect, but it’ll work even if it’s the physics engine that’s causing the player to move.

I can’t tell from what you’ve posted if Knight is the player, or if the player is some other object, so I can’t be more specific… but either of these approaches ought to work.