i have a problem. i want that if i move left or right, the camera slightly tilts left and right (on z axis).
now this works perfectly fine if i dont use my mouseLook but somehow together they wont work cause mouselook rotations are somehow overwriting my tilting. can someone give me a hint to how to pull this off? thx in advance
void Start()
{
initialRot = transform.localRotation;
// lock cursor
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
CameraRot();
// get mouse axis
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
// rotate player around y axis
player.Rotate(Vector3.up * mouseX);
// clamp cam rotation
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, topMaxRot, bottomMaxRot);
// rotate camera around x axis
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
void CameraRot()
{
float rotZ = -Input.GetAxis("Horizontal") * rotAmount;
Quaternion finalRot = Quaternion.Euler(0, 0, rotZ);
transform.localRotation = Quaternion.Lerp(initialRot, finalRot, smoothRotAmount);
}
It worked for me. Thanks a million! Do change the line that says
– CoalesceQuaternion finalRot = Quaternion.Euler(0, 0, rotZ);
toQuaternion finalRot = Quaternion.Euler(xRotation, 0, rotZ);
or else you cannot look up.YOU ARE A LIFE SAVER!!!! I've been looking EVERYWHERE for a solution! thank you so much!!
– Peaked