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 RodrigoRojas2244 · Aug 25, 2014 at 04:26 PM · planeclampclamped rotationflight sim

Trying to Clamp x rotation for flight simulation game

Hello, everybody. I'm currently making a flight simulation game. The plane begins with an x rotation of 0, and can change depending on player input to dive or climb. I'm trying to clamp it's rotation so that it can only go 45 degrees up and 45 degrees down. I've been using clamping, and have successfully restricted it from going any further than 45 degrees down, but whenever it goes below 0 (when trying to climb, and thus the rotation becomes negative) it just snaps back to 45 degrees, facing downward. This is my script:

 //Clamp values
 Vector3 clampVal;
 clampVal = new Vector3 (Mathf.Clamp(transform.eulerAngles.x,-45,45),transform.eulerAngles.y, transform.eulerAngles.z);
 transform.eulerAngles = clampVal;

Any ideas?

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 meat5000 ♦ · Aug 25, 2014 at 04:06 PM 0
Share

I imagine Unity prefers positive rotations. -45 would actually be 315 degrees and as this is higher than 45 it snaps to 45.

avatar image robertbu · Aug 25, 2014 at 04:28 PM 0
Share

Do not read from eulerAngles if at all possible. Even if as @meat5000 suggests, the angle is 315, there will come situations where the rotation will not work they way you want. I don't know how you are doing your rotation, but a better way would be to modify a Vector3 and then assign it to transform.eulerAngles. You could then do your clamping on the Vector3 before assigning it.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Math.f Clamp this 0 Answers

Clamping Vector3 2 Answers

Rotating and orbiting an game object with a stop angle 0 Answers

Bizzare problem with limiting camera veritcal rotation 2 Answers

How to clamp character rotation on Y and X axis? 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