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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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.