Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 $$anonymous$$oment () ftn if ( movement == true) { $$anonymous$$ovement(); } . void $$anonymous$$ovement() { 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.

Follow this Question

Answers Answers and Comments

98 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

Related Questions

How to limit the rotation of an object 2 Answers

Problem when i rotate a 2d object aroun Z-axis 1 Answer

How to rotate an object with animation? 0 Answers

accelerometer Rotation limiting 1 Answer

Why the player is not rotating and moving at the same time ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges