Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using Cinemachine;
  2. using UnityEngine;
  3.  
  4. public class CinemachineManualFreeLook : MonoBehaviour
  5. {
  6.     private CinemachineFreeLook freeLook;
  7.  
  8.     public float horizontalAimingSpeed = 20f;
  9.     public float verticalAimingSpeed = 20f;
  10.  
  11.     [Tooltip("This depends on your Free Look rigs setup, use to correct Y sensitivity,"
  12.         + " about 1.5 - 2 results in good Y-X square responsiveness")]
  13.     public float yCorrection = 2f;
  14.  
  15.     private float xAxisValue;
  16.     private float yAxisValue;
  17.  
  18.     private void Awake()
  19.     {
  20.         freeLook = GetComponent<CinemachineFreeLook>();
  21.     }
  22.  
  23.     private void Update()
  24.     {
  25.         float mouseX = Input.GetAxis("Mouse X") * horizontalAimingSpeed * Time.deltaTime;
  26.         float mouseY = Input.GetAxis("Mouse Y") * verticalAimingSpeed * Time.deltaTime;
  27.  
  28.         // Correction for Y
  29.         mouseY /= 360f;
  30.         mouseY *= yCorrection;
  31.  
  32.         xAxisValue += mouseX;
  33.         yAxisValue = Mathf.Clamp01(yAxisValue - mouseY);
  34.  
  35.         freeLook.m_XAxis.Value = xAxisValue;
  36.         freeLook.m_YAxis.Value = yAxisValue;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement