The game I’m working on currently has a massive bug, that is, if you move your mouse fast enough, you can get one of my game objects to glitch through walls. This game object rotates based on your mouse, but there is no max speed, so a fast enough mouse flick will get it through any wall. The entire principal of the game depends on the way that this object rotates, but I do not want it to be able to rotate at an infinite speed. Can anyone fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouseLook : MonoBehaviour
{
public float mouseSensativity = 100f;
//parent is the parent of this object, and is responsible for rotation on the y axis
public Transform parent;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
transform.localRotation = Quaternion.Euler(-90, 0f, 0f);
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensativity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensativity * Time.deltaTime;
parent.Rotate(Vector3.forward * -mouseX);
xRotation -= mouseY;
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}