Hi RealMTG,
If I understand what you are trying to accomplish, you would like to have the mouse X axis input map to vertical movement on the camera.
The first key issue is that Input.GetAxis("Mouse X") only returns delta move values, and zero when the mouse is not moving. Assigning this directly to X rotation is why your camera rotation keeps going back to zero.
You'll need to store the mouse X movement in an accumulator that retains its value across Update() calls to add to or remove from the mouse look each frame. Probably something like this:
float mouseAccumulator = 0;
void Update () {
...
mouseAccumulator += Input.GetAxis("Mouse X") * inputSensitivity;
mouseAccumulator = Mathf.Clamp(mouseAccumulator, -89, 89);
float x = mouseAccumulator;
float y = cameraHead.transform.eulerAngles.y;
float z = inputSensitivity * Time.deltaTime;
cameraHead.transform.localEulerAngles = new Vector3(x,y,z);
...
}
Second issue is that typically the local Euler angle vector is treated as an X, Y, Z rotation. Rotation on X is looking up/down, Y left/right, and Z rotating like a barrel roll. Your code is using mouse X, left right, to go up/down, which is odd. Also, your formula is setting Z to a not quite zero value each frame, which is odd, too. So I am guessing that what you really would want to do something like this:
Vector3 lookDirectionVector = Vector3.zero;
void Update () {
...
lookDirectionVector.x += Input.GetAxis("Mouse Y") * inputSensitivity; // Up & Down
lookDirectionVector.y += Input.GetAxis("Mouse X") * inputSensitivity; // Left & Right
lookDirectionVector.z = 0; // Roll
lookDirectionVector.x = Mathf.Clamp(lookDirectionVector.x, -89, 89);
cameraHead.transform.localEulerAngles = lookDirectionVector;
...
}
Finally, if you need to invert up/down movement, just change the X vector to -= instead of +=.
↧