Hi, I’m trying to make a simple first person controls, I want the movement direction you’re moving when you jump to stay the same while in the air. Right now I am able to completely control my character in the air with direction and speed, what would be the easiest way to go about it.
Here is my code:
void Update () {
//camera rotation Left and Right
float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
transform.Rotate(0, rotLeftRight, 0);
//camera rotation up and down with range
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation,0,0);
//movement
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
Vector3 speed = new Vector3 (sideSpeed, verticalVelocity, forwardSpeed);
//movement rotates with camera
speed = transform.rotation * speed;
//gravity
verticalVelocity += Physics.gravity.y * Time.deltaTime;
//jump
if(Input.GetButtonDown("Jump") && characterController.isGrounded){
verticalVelocity = jumpSpeed;
}
characterController.Move(speed * Time.deltaTime);
}