Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 PaxStyle · Jun 16, 2014 at 11:04 AM · mathfclamp

Mathf Clamp doesn't work

Good morning, I cannot set the max e min rotation limits, I followed an example that did so, but to me don't work..

Thanks for your support.

 public GameObject[] arm;
 
     float speedUp;
     float speedDown;
     Vector3 StartPosition;
    
 
 
     void Awake()
     {
         speedUp = 80f; 
         speedDown = 60f;
     }
 
  void Update () {
 //go up
         if (Input.GetKey (KeyCode.Z)) {
 
             arm[0].transform.Rotate(Vector3.right * Time.deltaTime*speedUp);
             speedUp = Mathf.Clamp(speedUp, 0f, 5f);
 
 
         }
 
         //go down
         if (Input.GetKey (KeyCode.X)) {
 
             arm[0].transform.Rotate(-Vector3.right * Time.deltaTime*speedDown);
             speedDown = Mathf.Clamp(speedDown, 0f, 5f);
 
 
         }
 }
Comment
Add comment · Show 11
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 Graham-Dunnett ♦♦ · Jun 16, 2014 at 11:04 AM 1
Share

What does "don't work" mean? What doesn't happen?

avatar image Magok_Stelios · Jun 16, 2014 at 12:05 PM 0
Share

if i'm not mistaken you need to add the rotate command after you do the clamp becasue right now the rotate is happening with the original speed, try to debug your speeds to watch their values if they actualy go higher than the max value

avatar image PaxStyle · Jun 16, 2014 at 03:21 PM 0
Share

Also if i set the mathf clamp, the rotation is still at 360°.. there aren't limits.

avatar image roojerry · Jun 16, 2014 at 03:40 PM 1
Share

What are you trying to clamp? The rotation? Right now you are clamping the speed up and down values to 5 each frame

avatar image PaxStyle · Jun 16, 2014 at 04:50 PM 0
Share

i would like to clamp the rotation..

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by flower · Jun 18, 2014 at 11:49 AM

If you want to clamp the rotation and i guessed your intentions right, you will need something like

 if (Input.GetKey (KeyCode.Z)) {
 
    Vector3 rot = Vector3.right * Time.deltaTime*speedUp;
    float rotX = Mathf.Clamp(rot.x, <minX>, <maxX>); // insert desired min/max values
    float rotY = Mathf.Clamp(rot.y, <minY>, <maxY>); // insert desired min/max values
    float rotZ = Mathf.Clamp(rot.z, <minZ>, <maxZ>); // insert desired min/max values
    arm[0].transform.Rotate(rot);
 
    // rest of code
 }
Comment
Add comment · Show 4 · 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 PaxStyle · Jun 18, 2014 at 02:11 PM 0
Share

@flower, thank you so much for your support, I insert the desired values just for try if it work, but any values that i inserted doesn't work. xD It's strange, but the rotation up and down is still at 360° why?

-Paolo

         //go up
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z)) {
         
         Vector3 rot = -Vector3.right * Time.deltaTime*speedUp;
         float rotX = $$anonymous$$athf.Clamp(rot.x, 0.1f, 0.5f); 
         arm[0].transform.Rotate(rot);



     }
     
     //go down
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X)) {
         
         Vector3 rot = Vector3.right * Time.deltaTime*speedUp;
         float rotX = $$anonymous$$athf.Clamp(rot.x, 0.1f, 0.5f); 
         arm[0].transform.Rotate(rot);


         
     }
avatar image roojerry · Jun 18, 2014 at 02:19 PM 0
Share
 arm[0].transform.Rotate(new Vector3(rotX,rotY,rotZ));
avatar image PaxStyle · Jun 18, 2014 at 03:44 PM 0
Share

Also with this the problem is not solved :\

avatar image PaxStyle · Jun 20, 2014 at 09:17 AM 0
Share

daily up ..:)

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

8 People are following this question.

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

Related Questions

Implementing mathf ? 1 Answer

Mathf.Clamp is not Clamping. 1 Answer

Modify distance with var? 1 Answer

limit accelerometer controlled rotation 1 Answer

How to use Mathf.Clamp with child objects? 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