Entire body moving with the camera
Whenever i move my camera left or right,the entire body does half a circle. I have no idea how to explain this. I just need a quick answer.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour {
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
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);
}
}
Answer by streeetwalker · Jul 07, 2020 at 02:04 PM
@Atskas Debug.Log xRotation before the clamp statement.
Note the documentation on GetAxis:
Returns the value of the virtual axis identified by axisName.
The value will be in the range -1...1 for keyboard and joystick input. If the axis is setup to be delta mouse movement, the mouse delta is multiplied by the axis sensitivity and the range is not -1...1.
So, probably there is already a sensitivity level applied to the input, and as a result xRotation is beyond the Clamp limits.
Your answer
Follow this Question
Related Questions
Rotate and more - Help 0 Answers
ANIMATION PROBLEM !! HELP !! 0 Answers
how to control my rigged model view with mouse? 0 Answers
I am new to unity and have problem with bricks game. 0 Answers
How do I make my camera Switch between 2 layer views? 0 Answers