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 /
  • Help Room /
avatar image
0
Question by mathacka · Nov 17, 2017 at 11:49 PM · mathf.clamprotations

So I'm trying to rotate an object from -35 degrees to 35 degrees, or rather 325 degrees to 35 degrees

So I'm trying to rotate an object from -35 degrees and 35 degrees, or rather 325 degrees to 35 degrees and I'm trying to lock the rotations there.

I have this code:

 void lockRotationUp()  {
         Rotation.x = transform.rotation.eulerAngles.x;
         Rotation.x = Mathf.Clamp (Rotation.x, 325,35);
         transform.localEulerAngles = new Vector3(Rotation.x, transform.localEulerAngles.y, transform.localEulerAngles.z);
 }

but it just flips between 325 and 35 degrees, no in-the-middle, but if I write it this way:

 void lockRotationUp()  {
         Rotation.x = transform.rotation.eulerAngles.x;
         Rotation.x = Mathf.Clamp (Rotation.x, -35,35);
         transform.localEulerAngles = new Vector3(Rotation.x, transform.localEulerAngles.y, transform.localEulerAngles.z);
     }

it freaks out when it hits zero, does anyone know how to properly lock the rotation from 325 degrees to 35 degrees?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by mathacka · Nov 18, 2017 at 02:42 AM

I fixed one aspect of it, the locking aspect, but occasionally it flips back to the other side, here's the next iteration of the code:

 void lockRotationUpDown()  {
         Rotation.x = transform.rotation.eulerAngles.x;
        
         if (Rotation.x < minBound)
         {
             Rotation.x += 360.0f;
         }
         Rotation.x = Mathf.Clamp(Rotation.x, 360.0f-minBound, 360.0f+minBound);
 
         if (Rotation.x >= 360.0f)
         {
             Rotation.x -= 360.0f;
         }
         transform.localEulerAngles = new Vector3(Rotation.x, transform.localEulerAngles.y, transform.localEulerAngles.z);
     }
Comment
Add comment · Show 2 · 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 mathacka · Nov 18, 2017 at 02:45 AM 0
Share

it works when the sensitivity of rotation is adjusted to be a low number, ie.

transform.Rotate(0,0,Time.deltaTime * sensitivity);

unfortunately a low number is too low.

avatar image mathacka · Nov 18, 2017 at 04:12 AM 0
Share

Ultimately I realized I've been doing this without the use of Quaternions, so I'm going to redo the entire rotation setup to use these and their functions.

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

118 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 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

Error CS1031 2 Answers

How can I make sprite stay in viewport and point towards the game object it is attached to? 1 Answer

Transform.rotation suddenly giving errors? 0 Answers

Limiting the movement of a player object moved by transform.translate (Unity 5) 0 Answers

Why does the gameobject "bounce back", and start rotating the opposite direction once it has reached its mathf.clamp rotation limit? 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