• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Charlie_H · Dec 26, 2018 at 11:49 AM · rotationrotate objectlimit

limit rotation to 90 degree on one axis

i am making a game in which it first scale the plank on touchPhase.begin and Rotate to z-axis to 90 degree on touchPhase.ended but when i again try to end touchPhase it rotate to 180 degree . i want to limitize to 90 degree only. what should i do?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadowUser19 · Dec 26, 2018 at 12:24 PM 0
Share

can you the code you are currently using to do the rotation?

avatar image Charlie_H ShadowUser19 · Dec 26, 2018 at 01:09 PM 0
Share

this.gameObject.transform.Rotate(new Vector3(90,0,0))

avatar image Charlie_H · Dec 27, 2018 at 09:34 AM 0
Share

THanks @mlnczk & @ShadowUser19 it worked in this way. i made variable name as var = movement; and when movement true,i called the Moment () ftn if ( movement == true) { Movement(); } . void Movement() { Debug.Log("X");

     if (this.gameObject.transform.eulerAngles.x >= 89.5f)
             movement = false;

     else
     {        
         float move = Time.deltaTime + speed;
         transform.Rotate (Vector3.right * move);
      }

 }

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ShadowUser19 · Dec 26, 2018 at 01:50 PM

I haven't tested it myself, but I think what you are looking for are eulerangles:

 var xRotation = this.gameObject.transform.rotation.eulerAngles.x;
 if (xRotation <= 90)
 {
     this.gameObject.transform.Rotate(new Vector3(90,0,0))
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mlnczk · Dec 27, 2018 at 08:37 AM

You should use Mathf.Clamp described here : https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html.

You want to do it this way :

float limitedRotation = Mathf.Clamp(limitedRotation, 0, 90); And then in code where you want to limit z axis you just put clamped float -> limitedRotation.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Charlie_H · Dec 27, 2018 at 09:37 AM

THanks @mlnczk & @ShadowUser19 it worked in this way. i made bool variable name as movement and when movement true,i called the Moment () ftn . " bool movement = false; void Update() { if ( movement == true) { Movement(); } . } void Movement() { if (this.gameObject.transform.eulerAngles.x >= 89.5f) { movement = false; } else {
float move = Time.deltaTime + speed; transform.Rotate (Vector3.right * move); }

} "

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mlnczk · Dec 27, 2018 at 09:45 AM 0
Share

Using clamp would be much more efficient. Thats a lot of codes and calling methods for just limiting rotation degrees. Anyways good luck !

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best rotation function to use 1 Answer

Have an object continuously rotate towards another 1 Answer

how to limit rotation 2 Answers

Limiting rotation of object, specifically using scroll wheel 2 Answers

How can I lock the rotation angle at a certain point? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges