Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Free Look Camera Unity 3D

Discussion in 'Input System' started by shadermanger, Dec 21, 2020.

  1. shadermanger

    shadermanger

    Joined:
    Sep 21, 2020
    Posts:
    21
    I Want to Rotate My Camera around an object. its working fine but when rotation of x-axis done almost 90 degree the rotation for y-axis invert.


    Code (CSharp):
    1. public void rotateCharacter()
    2.     {
    3.         Vector2 currentOffset, startOffset;
    4.         if (Input.GetMouseButton(0) && EventSystem.current.currentSelectedGameObject == null && (GlobalValues.isGestureUnlock == true || GlobalValues.isDone == true))
    5.         {
    6.             if (isRotating == true)
    7.             {
    8.                 perviousTouch = currentTouch;
    9.                 currentTouch = Input.mousePosition;
    10.  
    11.                 startOffset = currentTouch - startTouch;
    12.                 currentOffset = currentTouch - perviousTouch;
    13.  
    14.                 if (Mathf.Abs(startOffset.x) > 3)
    15.                 {
    16.  
    17.                     transform.RotateAround(GlobalValues.character.transform.position, Vector3.down, (-currentOffset.x * rotationSpeed));
    18.                 }
    19.                 if (Mathf.Abs(startOffset.y) > 3)
    20.                 {
    21.                     transform.RotateAround(GlobalValues.character.transform.position, Vector3.right, (-currentOffset.y * rotationSpeed));
    22.                 }
    23.             }
    24.             else
    25.             {
    26.                 isRotating = true;
    27.                 currentTouch = startTouch = Input.mousePosition;
    28.             }
    29.         }
    30.     }