This is a short question, how can I improve the camera script, I do not need a wiki page about, just edit the piece of code as I have seen it (and it is way too complicated for me to understand).
if (CamX < 0)
{
Camera.transform.Rotate(0, -1, 0);
}
if (CamX > 0)
{
Camera.transform.Rotate(0, 1, 0);
}
if (CamY > 0)
{
Camera.transform.Rotate(-1, 0, 0);
}
if (CamY < 0)
{
Camera.transform.Rotate(1, 0, 0);
}
PS. I know using a bunch of if’s is messy, but if I make it else if then it goes messy, you’ll know why. Sorry for the laggy video quality if it is like 2 fps, I hope you can tell what is wrong with camera.
A way to prevent that from happening is to always set the target rotation, not apply some rotation for every small change. I believe (?) the problem here has to do with the accumulation of small imprecisions or something like that.
This code should do what you want it to:
//In Update()
Vector2 mouseInput = new Vector2(Input.GetAxisRaw("Mouse Y"), Input.GetAxisRaw("Mouse X"));
mouseDelta += mouseInput; // mouseDelta being a Vector2 defined outside of Update()
transform.eulerAngles = new Vector3(-mouseDelta.x, mouseDelta.y, 0);
You may wanna lock the rotation to some range tho.