Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using TreeEditor;
- using UnityEngine;
- public class MouseMovement : MonoBehaviour
- {
- public float mouseSens = 480f;
- public Camera viewCamera;
- float xRot = 0f;
- float yRot = 0f;
- public float maxLookUp = -85;
- public float maxLookDown = 85;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- // Update is called once per frame
- void Update()
- {
- // register input
- float mouseX = Input.GetAxis("Mouse X") * mouseSens * Time.deltaTime;
- float mouseY = Input.GetAxis("Mouse Y") * mouseSens * Time.deltaTime;
- // vertical look, clamped cos your ass aint that flexible
- xRot -= mouseY;
- xRot = Mathf.Clamp(xRot, maxLookUp, maxLookDown);
- // horizontal look so you can hit them clips
- yRot += mouseX;
- transform.localRotation = Quaternion.Euler(0f, yRot, 0f);
- viewCamera.transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment