How do i create c# script that allows me to move when not grounded?

The script doesnt allow me to move unless grounded

2190397–145328–PlayerMovement.cs (1.03 KB)

Try my character controller tutorial. It will get a nice controller for you in about 20 minutes. :slight_smile:

Character Controller in 20 Minutes
How to Jump

@ConfusedEdBoy The problem with your script is that you ignore all input whenever the max velocity is reached:

So, if you are falling quickly, you won’t be able to apply additional input:

if (GetComponent<Rigidbody> ().velocity.magnitude < maxSpeed)

An alternative approach would do this:

  • Always apply the input which does not affect your y position
  • Check the x and z magnitude of the velocity to see if their combined magnitude is greater than max speed (you can use their values to create a Vector2).
  • Scale the x and z back so it has maximum speed (you will need to use the normalized value of the Vector2 and scale it to max speed)