Search Unity

Smooth camera rotation on mobile and pc when GetMouseButton()?

Discussion in 'Scripting' started by Bongmo, Mar 5, 2015.

  1. Bongmo

    Bongmo

    Joined:
    Jan 18, 2014
    Posts:
    155
    Hi,

    I wrote this script here:
    Code (CSharp):
    1.     if (Input.GetMouseButton (0)) {
    2.  
    3.         camRotation.x = Input.GetAxis("Mouse X");
    4.         camRotation.y = Input.GetAxis("Mouse Y");
    5.  
    6.         camRotation.x *= rotationSpeed.x;
    7.         camRotation.y *= rotationSpeed.y;
    8.         camRotation *= Time.deltaTime;
    9.      
    10.         transform.Rotate( 0, camRotation.x, 0, Space.World );
    11.  
    12.         transform.Rotate( -camRotation.y, 0, 0 );
    13.      
    14.     }
    This code works, but the rotation on my mobile device is not smooth. It's a little bit jerky.

    How can I make it smoother?

    And I want, that the camera rotates slowly or fast depending on the swipe.

    Can somebody give me some tips?

    Thanks.