Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to Fix Rotation Snaps?

Discussion in 'Scripting' started by jameskxia, Jul 28, 2022.

  1. jameskxia

    jameskxia

    Joined:
    Feb 6, 2019
    Posts:
    2
    I tried to get full camera rotation by putting horizontal rotation on the right button and vertical rotation on the middle button, but because there are 0s for the other two axes the camera snaps back to the original height/direction whenever I switch from one button to the other.

    How do I get smooth full camera rotation on one button?

    This is the tutorial I finished when I decided to try getting 3d rotation.




    private void RotateCamera(InputAction.CallbackContext obj)
    {
    if (!Mouse.current.middleButton.isPressed)
    return;
    float inputValue = obj.ReadValue<Vector2>().x;
    transform.rotation = Quaternion.Euler(inputValue * maxRotationSpeed + transform.rotation.eulerAngles.x, 0f, 0f);
    }
    private void RotateCameraa(InputAction.CallbackContext obj)
    { if (!Mouse.current.rightButton.isPressed)
    return;
    float inputValuee = obj.ReadValue<Vector2>().y;
    transform.rotation = Quaternion.Euler(0f, inputValuee * maxRotationSpeed + transform.rotation.eulerAngles.y, 0f);
    }
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
  3. jameskxia

    jameskxia

    Joined:
    Feb 6, 2019
    Posts:
    2
    Thanks, I will! I'm just curious to see if I can salvage some value from what I have.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Excellent, I can respect that.

    I see you using
    .eulerAngles
    above... they can be problematic, or at the least tricky to reason about. Allow me to gently pry open a fold of your great brain and drop this little tidbit in for your consideration:

    https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html