#My FPS camera controller is working
1 messages · Page 1 of 1 (latest)
Try this:
public class SimpleMouseLook : MonoBehaviour
{
// Sensitivity of mouse movement
public float sensitivity = 1f;
// Clamp vertical rotation angle
public float clampAngle = 85f;
// Current rotation angles
private float xRot = 0f;
private float yRot = 0f;
void Start()
{
// Get initial rotation angles from transform
Vector3 rot = transform.localRotation.eulerAngles;
xRot = rot.x;
yRot = rot.y;
}
void Update()
{
// Get mouse movement delta
float mouseX = Input.GetAxis("Mouse X");
float mouseY = -Input.GetAxis("Mouse Y");
// Apply sensitivity
mouseX *= sensitivity;
mouseY *= sensitivity;
// Update rotation angles
xRot += mouseY;
yRot += mouseX;
// Clamp vertical angle
xRot = Mathf.Clamp(xRot, -clampAngle, clampAngle);
// Apply rotation to transform
transform.rotation = Quaternion.Euler(xRot, yRot, 0f);
}
}```
This script is to be attached to the camera btw. It doesn't do the player rotation, but that should be trivial.
Note tjat I filled in the values in the inspector. I'll vheck it out more soon. Thanks!
Also, it already works just fine now. What I need fixed is that downward whiplash
I have already done it and it works perfectly