Need to be able to change movement direction in air (C#)

I need to make the script allow for you to change direction in the air. When someone jumps and holds forward, they no longer go in the direction the camera is pointing but sticks to its path till it hits the floor. I want it to always go relative of where the camera points so if you jump you can turn it midair, cpm movement style (Quake).

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {
    //Variables
    public float speed = 6.0F;
    public float jumpSpeed = 8.0F; 
    public float gravity = Physics.gravity.y;
    private Vector3 moveDirection = Vector3.zero;
 
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        // is the controller on the ground?
        if (controller.isGrounded) {
            //Feed moveDirection with input.
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            //Multiply it by speed.
            moveDirection *= speed;
            //Jumping
            if (Input.GetButton("Jump")) moveDirection.y = jumpSpeed;			
			
		}
		
		
        //Applying gravity to the controller
        moveDirection.y -= gravity * Time.deltaTime;
        //Making the character move
        controller.Move(moveDirection * Time.deltaTime);
    }
}

I am aware this is a script from Unity’s codebase :wink:

if (controller.isGrounded)

That is the culprit for why you can’t move it while in the air. Inside this if statement is where the controller takes in input for movement. Either move these lines out of that statement:

            //Feed moveDirection with input.
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            //Multiply it by speed.
            moveDirection *= speed;

Or use an else block and alter the speed multiplier, and copy/paste those lines if you want them to change direction at a different rate when in the air.