Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class FPSMouseController : MonoBehaviour
- {
- [SerializeField] private float _horizontalSpeedMultuplayer = 1;
- [SerializeField] private float _verticalSpeedMultuplayer = 1;
- private float _horizontalAngle;
- private float _verticalAngle;
- private void LateUpdate()
- {
- var x = Input.GetAxis("Mouse X");
- var y = Input.GetAxis("Mouse Y");
- _horizontalAngle += x * _horizontalSpeedMultuplayer;
- _verticalAngle -= y * _verticalSpeedMultuplayer;
- Quaternion horizontalRotation = Quaternion.AngleAxis(_horizontalAngle, Vector3.up);
- Quaternion verticalRotation = Quaternion.AngleAxis(_verticalAngle, Vector3.right);
- transform.rotation = horizontalRotation * verticalRotation;
- }
- }
Add Comment
Please, Sign In to add comment