Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraController : MonoBehaviour {
- Vector2 mouseCam;
- Vector2 smoothVect;
- public float sensitivity = 5f;
- public float smoothing = 2f;
- public bool camLock = false;
- public GameObject Player;
- public GameControls input;
- public Vector2 deltaInput;
- void Awake()
- {
- input = new GameControls();
- input.InGame.Look.performed += ctx => deltaInput = ctx.ReadValue<Vector2>();
- }
- void Start ()
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- // Update is called once per frame
- void Update ()
- {
- Debug.Log("Mouse Delta: " + deltaInput);
- //Old code
- /*if (!camLock)
- {
- var mouseDir = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
- mouseDir = Vector2.Scale(mouseDir, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
- smoothVect.x = Mathf.Lerp(smoothVect.x, mouseDir.x, 1f / smoothing);
- smoothVect.y = Mathf.Lerp(smoothVect.y, mouseDir.y, 1f / smoothing);
- mouseCam += smoothVect;
- mouseCam.y = Mathf.Clamp(mouseCam.y, -66, 66);
- transform.localRotation = Quaternion.AngleAxis(-mouseCam.y, Vector3.right);
- Player.transform.localRotation = Quaternion.AngleAxis(mouseCam.x, Player.transform.up);
- if(recoil > 0f)
- {
- recoil -= (Time.deltaTime * 2);
- }
- else
- {
- recoil = 0f;
- }
- }*/
- if (!camLock)
- {
- //mouseDir = Vector2.Scale(mouseDir, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
- /*smoothVect.x = Mathf.Lerp(smoothVect.x, mouseDir.x, 1f / smoothing);
- smoothVect.y = Mathf.Lerp(smoothVect.y, mouseDir.y, 1f / smoothing);
- mouseCam += smoothVect;*/
- //mouseCam.y = Mathf.Clamp(mouseCam.y, -66, 66);
- Vector2 fullRot = new Vector2(deltaInput.y, 0) * Time.deltaTime;
- Vector2 selfRot = new Vector2(0, deltaInput.x) * Time.deltaTime;
- /*transform.localRotation = Quaternion.AngleAxis(-deltaInput.y, Vector3.right);
- Player.transform.localRotation = Quaternion.AngleAxis(deltaInput.x, Player.transform.up);*/
- transform.Rotate(selfRot);
- Player.transform.Rotate(fullRot);
- if (recoil > 0f)
- {
- recoil -= (Time.deltaTime * 2);
- }
- else
- {
- recoil = 0f;
- }
- }
- }
- void OnEnable()
- {
- input.Enable();
- }
- void OnDisable()
- {
- input.Disable();
- }
- private float recoil = 0.0f;
- public void StartRecoil(float recoilFeedthrough)
- {
- recoil = recoilFeedthrough;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement