I’m extremely new to unity, and I’m trying to make a simple character controller with a rigidbody, but my camera movement is so extremely laggy.
void Look()
{
//Gets the mouse input and multiplies it by the sensitivity
float horizontal = Input.GetAxis("Mouse X") * sensitivity;
float vertical = Input.GetAxis("Mouse Y") * sensitivity;
//Variable which keeps track of the rotation of the camera on the y
yClamp += vertical;
//Rotates the camera and player
camera.transform.Rotate(-Vector3.right * vertical);
transform.Rotate(Vector3.up * horizontal);
//Prevents the camera from rotating upside down
if(yClamp >= 90)
{
Clamp(camera.transform, 270, "x");
vertical = 0;
yClamp = 90;
}
else if (yClamp <= -90)
{
Clamp(camera.transform, 90, "x");
vertical = 0;
yClamp = -90;
}
}
//Clamps the rotation of a given transform on the given axis by the given number
void Clamp(Transform obj, float value, string axis)
{
Vector3 eulerAngles = obj.eulerAngles;
switch (axis)
{
case "x":
eulerAngles.x = value;
break;
case "y":
eulerAngles.y = value;
break;
}
obj.eulerAngles = eulerAngles;
}
Any help is appreciated, thanks in advance.