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 thornekey · Mar 15, 2014 at 09:57 AM · c#rotationminimum

Restrict min/max rotation STILL wont work

How would I restrict the rotation so that when i get to a certain amount it stays there.

here is what i have

     minRotation variable?
  
     if (Input.GetKey(KeyCode.LeftArrow)) {
         transform.Rotate(0,Time.deltaTime * 100,0);
     }
         if(SOMETHING == minRotation) {
             stay at min rotation
         }
 

i want it to only check the Y rotation

Comment
Add comment · Show 2
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 thornekey · Mar 15, 2014 at 11:34 AM 0
Share

bump still dont know how

avatar image thornekey · Mar 15, 2014 at 02:24 PM 0
Share

this is what ive got atm, now and still cant figure it out:

 public Vector3 myEuler = Vector3.zero;
     public float rotVel;
     
     void Start () {
     myEuler.x = transform.eulerAngles.x;
 
     }
  
     void Update () {
         
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow)) {
             transform.Rotate(0,Time.deltaTime * 50,0, Space.World);
         }
                     
         else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow)) {
             transform.Rotate(0,Time.deltaTime * -50,0, Space.World);
         }    
         
         else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow)) {
             myEuler.x += rotVel * Time.deltaTime;
         }
                     
         else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow)) {
             myEuler.x -= rotVel * Time.deltaTime;
         }    
     }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Destran · Mar 15, 2014 at 10:07 AM

you could use Mathf.Clamp, so you could try something like:

 function Update ()
 {
 transform.rotation = Vector3(Mathf.Clamp(transform.rotation, desired minimum rotation, desired maximum rotation), 0, 0);
 }
 
 // this would affect your x rotation.  If you wanted it in your y or z you could just move the zeroes around so like this for Y rotation:
 
     
 function Update ()
 {
 transform.rotation = Vector3(0,Mathf.Clamp(transform.rotation, desired minimum rotation, desired maximum rotation), 0);
 }
Comment
Add comment · Show 6 · 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 thornekey · Mar 15, 2014 at 10:10 AM 0
Share

how would i store it in a variable and check if its the same as something else though?

avatar image Destran · Mar 15, 2014 at 10:17 AM 0
Share

well I'm fairly new to scripting but in your instance you wouldn't need to store it in a variable. Because once it was over a certain rotation it would clamp to your desired $$anonymous$$/max rotation.

So from the example you gave what you would would need:

 function Update ()
 {
 transform.rotation = Vector3(0,$$anonymous$$athf.Clamp(transform.rotation, desired $$anonymous$$imum rotation, desired maximum rotation), 0);
 }
 
 
 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow)) {
     transform.Rotate(0,Time.deltaTime * 100,0);
 }
avatar image thornekey · Mar 15, 2014 at 10:19 AM 0
Share

im gettin this error:

 Expression denotes a `type', where a `variable', `value' or `method group' was expected
 
avatar image Destran · Mar 15, 2014 at 10:25 AM 0
Share

it appears I led you astray :'( I was going almost entirely off of http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.Clamp.html. Let me fix this and then get back to you

avatar image thornekey · Mar 15, 2014 at 10:59 AM 0
Share

ok tahts fine

Show more comments

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

21 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Is it possible to add a point to the score, everytime the Player rotates 180°? 2 Answers

Rotating Character 1 Answer


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