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

How to ONLY allow user to rotate a game object clockwise?

Discussion in 'Scripting' started by MiaoBolverk, Apr 26, 2018.

  1. MiaoBolverk

    MiaoBolverk

    Joined:
    Feb 6, 2018
    Posts:
    26
    I have a game object which can be rotated by the user:
    Code (csharp):
    1. public class RotatableObject : MonoBehaviour
    2.     {
    3.         private void RotateAccordingTo(Hand hand)
    4.         {
    5.             Quaternion desiredRotation = hand.CurrentRotation;
    6.             desiredRotation.y = 0;
    7.             desiredRotation.z = 0;
    8.             this.transform.localRotation = desiredRotation;
    9.         }
    10.     }    
    Right now, the user is able to rotate it both counter-clockwise and clockwise.

    I wish to modify the code so that the object does not rotate when the user tries to turn it counter-clockwise. It rotates only when the user is turning it clockwise.

    How can I achieve this effect?
     
  2. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
    Not sure if i get you right but

    Code (CSharp):
    1.     if(desiredRotatio.eulerAngles.y < this.transform.rotation.eulerAngles.y)//could be the wrong axis
    2.             return;
    could be it.