Question by
jjmerrill2004 · Dec 23, 2020 at 08:34 AM ·
camera rotatefps controller
FPS Camera rotation - Character Controler
I am making a character controller for a fps game and the look scripts is only supposed to rotate the character body on the Xaxis but not on the Yaxis yet it rotates the body in the Y and Xaxis.
I have no prior experience with unity code - (C#)
my current code:
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
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);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
Comment
Your answer
Follow this Question
Related Questions
Look Left or right but keep walking forward 0 Answers
how to stop character spin fps,How to stop character spin fps 0 Answers
How to configure my camera ?? 0 Answers
i am tying to build a fps controller from scratch and cant seem to get him to look up or down 0 Answers
Tilt camera left or right on keyboard input,Tilt camera when player moves left or right 0 Answers