#Camera's vertical rotation smoothly

1 messages · Page 1 of 1 (latest)

tender geyser
#

How can I add the xRotation value to the game without breaking the camera rotation.. If I use targetCameraRotation, the camera spins so fast on all axis that you can't really use that. For now I have set targetPlayerRotation for the rotation of camera. So the camera can now rotate horizontally as supposed to but I want to move it vertically as well.```cs
void Update()
{
UpdateCameraPosition();
float mouseX = Input.GetAxis("Mouse X") * (mouseSensitivity * 10) * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * (mouseSensitivity * 10) * Time.deltaTime;

xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);

targetCameraRotation *= Quaternion.Euler(xRotation, mouseX, 0f);

targetPlayerRotation *= Quaternion.Euler(0f, mouseX, 0f);

player.rotation = Quaternion.Lerp(player.rotation, targetPlayerRotation, playerRotationSmoothness * Time.deltaTime);

transform.rotation = Quaternion.Lerp(transform.rotation, targetPlayerRotation, playerRotationSmoothness * Time.deltaTime);

}

fierce summit
#

this is how I do my camera rotation iirc ```cs
public float mouseSensitivity;

Vector2 look = Vector2.zero;

void Update() {
look.x += Input.GetAxisRaw("Mouse X") * mouseSensitivity;
look.y = Mathf.Clamp(look.y - Input.GetAxisRaw("Mouse Y") * mouseSensitivity, -90f, 90f);

transform.rotation = Quaternion.Euler(look.y, look.x, 0f);
}

#

should be easy to edit to add the smoothing stuff you have

#

* Time.deltaTime isn't required for Input.GetAxis mouse stuff

fierce summit
#

for the player you just do the same I guess but replace the look.y with 0

fierce summit
tender geyser
#

Thank you very much @fierce summit this worked!

fierce summit