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

Mouse X drag rotates object in opposite direction?

Discussion in 'Scripting' started by taelor, Apr 12, 2018.

  1. taelor

    taelor

    Joined:
    Apr 22, 2015
    Posts:
    6
    I'm not sure how to resolve this and I'm hoping someone can help...in the main game scene, everything works as intended, but in the lobby scene where you choose an avatar, I have the following code set up:
    Code (CSharp):
    1. private void Update()
    2.     {
    3.         if(Input.GetMouseButton(0))
    4.             transform.Rotate(new Vector3(0.0f,Input.GetAxis("Mouse X")*sensitivityX, 0.0f));
    5.     }
    It works perfectly except when you drag the mouse to the left, the avatar rotates right, and if you drag right, it rotates left...is there any way to code in the script (because I don't want to change anything that will interfere with the main scene) to reverse the rotation it thinks it should be doing? Rotation is simple enough, but I'm lost when it comes to direction..one way would be negative and the other positive (I think), but beyond that, I'm a little lost.
     
  2. duisti

    duisti

    Joined:
    Nov 29, 2017
    Posts:
    52
    try to multiply your Y calculation there with -1f

    Or, assign a pivot for the object and flip it

    Code (CSharp):
    1. Input.GetAxis("Mouse X")*sensitivityX*-1f
     
  3. taelor

    taelor

    Joined:
    Apr 22, 2015
    Posts:
    6
    That seems to interfere with the sensitivity (set as public float to 10F) and does this weird hiccup before continuing as before (drag sends rotation in opposite direction). I'll look at assigning a pivot, thanks.