Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question "Drag to Rotate" invert when behind object. Help.

Discussion in 'Getting Started' started by Pollawat, Jan 29, 2022.

  1. Pollawat

    Pollawat

    Joined:
    Aug 27, 2016
    Posts:
    192
    Hollo. I'm a newbie.

    I try to follow a code from the internet to create some kind of an axis rotation system.



    As you can see here it works fine until I turn it around to the back of it and the axis rotation seems to be inverted (I don't want it to be like that).

    Code (CSharp):
    1.     public GameObject motherObject;
    2.     public float rotSpeed = 5;
    3.  
    4.  
    5.  
    6.     private void OnMouseDrag()
    7.     {
    8.         float rotX = Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;
    9.         float rotY = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
    10.  
    11.         motherObject.transform.Rotate(Vector3.forward, rotY, Space.Self);
    12.  
    13.     }
    I spend all day trying to find a solution until I end up here.

    Thank you.
     
    Last edited: Jan 30, 2022