- Home /
Tilt camera while moving smoothly
Hi, i want to make a first-person-camera for controlling a submarine. Therefore i need smooth moves and when i turn left i also want to tilt the camera left.
My code looks like this:
tiltAroundZ -= (Input.GetAxis("Mouse X")*15) * tiltAngle * invertX_factor;
cummulativeRotation.x -= Input.GetAxis("Mouse Y") Time.deltaTime rotationFactor invertY_factor; cummulativeRotation.y += Input.GetAxis("Mouse X") Time.deltaTime rotationFactor invertX_factor;
if (Mathf.Abs(cummulativeRotation.x) > 90) cummulativeRotation.x -= cummulativeRotation.x%90;
Quaternion targetRotation = Quaternion.Euler(cummulativeRotation.x, cummulativeRotation.y, tiltAroundZ); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
The camera moves smoothly but i really have troubles with the "tilt". Does anyone has an idea how to achieve this behaviour?
Thanks a lot!