Search Unity

Question Mouse Look Help

Discussion in 'Input System' started by cookecaius, Feb 26, 2023.

  1. cookecaius

    cookecaius

    Joined:
    Dec 3, 2022
    Posts:
    1
    Hi! I'm sure this question has been asked before but I couldn't find it after a lot of searching. Basically, every script I make for TPS or FPS cameras ends up without the ability to fine control the movement. In every game, the quicker you move your mouse the faster the camera will respond and if you just barely push the mouse along the X axis the game's viewport should also only move a small amount. However, the InputSystem methods and the old Input Manager way of doing things seems to give me the effect of only able to move a set amount without factoring in acceleration. I think this is due to the axes being normalized, but I'm not sure how to get around this. Also, no matter what I do the camera ends up choppy during very fast flicks or very small movements. If anyone can help me figure out how to achieve the fine control seen in games like CoD that would be great. Here's something I had most recently and it worked alright but still a bit choppy. Thanks!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerLook : MonoBehaviour
    6. {
    7.     private float xRotation = 0f;
    8.     [SerializeField] Camera cam;
    9.    
    10.     public float xSensitivity = 30f;
    11.     public float ySensitivity = 30f;
    12.     public void ProcessLook(Vector2 input)
    13.     {
    14.         xRotation -= (input.y * Time.deltaTime) * ySensitivity;
    15.         xRotation = Mathf.Clamp(xRotation, -80, 80);
    16.  
    17.  
    18.         cam.transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
    19.  
    20.        
    21.         transform.Rotate(Vector3.up * (input.x * Time.deltaTime) * xSensitivity);
    22.  
    23.     }
    24. }
    For this script the Vector2 parameter is passed in another script where I'm using the InputSystem to get a Vector2 from the mouse movement.