I’m making a diving FPS character and it moves in the direction in wich the camera is looking.
With the mouse you rotate the player (a sphere with a camera inside) in the X and Y axis, but it also rotates the Z axis and make a weird movement, I want to lock the Z rotation.
Here is the code of the camera movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaterMouseLook : MonoBehaviour {
public float MouseSensitivity = 100f;
public Transform playerBody;
public float xRotation = 0f;
void Start(){
Cursor.lockState = CursorLockMode.Locked;
}
void Update () {
if (Input.GetMouseButtonDown (0)){
Cursor.lockState = CursorLockMode.Locked;
}
float mouseX = Input.GetAxis ("Mouse X") * MouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis ("Mouse Y") * MouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp (xRotation, -90f, 90f);
playerBody.Rotate (Vector3.up * mouseX);
playerBody.Rotate (-Vector3.right * mouseY);
//I WANT TO LOCK THE Z AXIS OF THE ROTATION
}
}