ARTICLE AD BOX
I'm trying to improve my character's mouse movement. This is in a first person scenario, the horizontal movement seems perfect but at random times the look up/look down mechanic go haywire and act on their own. The functions I used for Horizontal and Vertical are the same but I'm not sure what could be causing this.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseMovement : MonoBehaviour { public float mouseSensitivity = 200f; float xRotation = 0f; float YRotation = 0f; void Start() { //Locking the cursor to the middle of the screen and making it invisible Cursor.lockState = CursorLockMode.Locked; } void Update() { if (!InventorySystem.Instance.isOpen ) //remove these) && !CraftingSystem.Instance.isOpen) { float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; //control rotation around x axis (Look up and down) xRotation -= mouseY; //clamp the rotation so we dont Over-rotate (like in real life) xRotation = Mathf.Clamp(xRotation, -90f, 90f); //control rotation around y axis (Look up and down) YRotation += mouseX; //applying both rotations transform.localRotation = Quaternion.Euler(xRotation, YRotation, 0f); } } }124k31 gold badges285 silver badges492 bronze badges
331 silver badge3 bronze badges
New contributor
the jsto is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
Yep it seems removing
Time.deltaTimewas the issue. the below code is working way better but on a lower
public float mouseSensitivity = 3f;Please see the final mouse code changes here:
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;Thanks again for the help!
331 silver badge3 bronze badges
New contributor
the jsto is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Explore related questions
See similar questions with these tags.
