- Home /
why when my first person camera looks at to many gameobjects it becomes really sensitive?
i have a problem. i copied a camera script off of a video and it seemed to work fine, until i started putting gameObjects in the scene... if my camera looks at a gameobject, it becomes more sensitive.(it makes my camera able to look around really fast) and the more objects the camera is looking at the more sensitive it becomes. please help! here is my script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraLook : MonoBehaviour {
float rotationOnX;
float mouseSensitivity = 90f;
public Transform player;
// Start is called before the first frame update
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
float m_X = Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity;
rotationOnX -= mouseY;
rotationOnX = Mathf.Clamp(rotationOnX, -90, 90);
transform.localEulerAngles = new Vector3(rotationOnX, 0f, 0f);
player.Rotate(Vector3.up * m_X);
}
}
Answer by Eno-Khaon · Aug 22, 2020 at 08:44 PM
float mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
float m_X = Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity;
Input.GetAxis("Mouse [axis]") gives you the amount of movement provided in the last frame. As a result, it's already being scaled relative to your framerate. With that in mind, you can remove the Time.deltaTime scaling and decrease your sensitivity by ~60 (assuming common refresh rate coupled with V-Sync).
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;