How do I say player is moving?

Just a simple question I’m trying to figure out here, got an if statement where I want to basically say if the player is grounded and currently moving forward direction (z), do this. Example:

if(charactercontroller.isGrounded && PLAYER_IS_CURRENTLY_MOVING_FORWARD/player pressing W)
  then do this

So my problem is I just don’t remember what the movement code is and having a lot of trouble googling answers because I can’t quite word it well. Thanks for the help!

The reason I am asking is because I’ve correctly coded a sprint toggle. However, the animation plays even when the character isn’t moving so I just want to stop that with the &&.

One way is to check CharacterController.velocity. You can also compare the velocity to the forward vector to make sure the movement is forward.

if (charactercontroller.velocity.magnitude > movementThreshold && Vector3.Angle(transform.forward, charactercontroller.velocity) <= rotationThreshold) {
    Debug.Log("I'm moving generally in the forward direction");

‘movementThreshold’ and ‘rotationThreshold’ are variables you define and initialize to represent how much something is moving before it is considered to be moving and how close an angle before it is considered moving forward.