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