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 Qasem2014 · Mar 06, 2015 at 10:53 AM · rotationlimitdegree

Problem With 360 Rotation Degrees

hi

i have a player with a camera as child and 2 UI button that rotate the camera up and down . when "up button" pressed , RTU (boolean) variable set to TRUE and in update function it rotate the camera up and when "down button" pressed , RTD (boolean) variable set to TRUE and in update function it rotate the camera down . and when they release , RTU and RTD set to FALSE .

here is my code :

 var MyCamera:gameobject; //Camera
 var RTD:boolean=false; var RTD:boolean=false;
 function Update()
 {
     if(RTU == true )
     MyCamera.transform.Rotate(Time.deltaTime*20,0,0);
     if(RTD == true )
     MyCamera.transform.Rotate(-Time.deltaTime*20,0,0);
 }

now the problem is here : i cant tell the function , rotate the camera just +45 And -45 degree . transform.Rotate is from 0 to 360 and it don't have -45 value . -45 is 315 in transform.Rotate .

<< here is a picture that make my question more clear : >>

alt text

like picture , before 0 come 360 and i want to rotate my camera between 315 and 45 degree (+45 to -45) . how can i do that ?

<< Excuse Me For My Bad English , If The Question Is Not Clear , Just Tell Me >>

ax.jpg (13.1 kB)
Comment
Add comment · Show 1
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 Erdem-KAYA · Mar 25, 2016 at 11:22 AM 0
Share

Thank you for Quaternion.RotateTowards advice.

2 Replies

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

Answer by juanma_teso · Mar 06, 2015 at 12:22 PM

Set a condition that prevents be under 315 and over 45: if(camera.rotation.eulerAngles.x >315){ rotate the camera; } if(camera.rotation.eulerAngles.x < 45){ rotate the camera; } This will work if transform floats to int (Mathf.Floor)

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 Qasem2014 · Mar 06, 2015 at 12:44 PM 0
Share

that's what im looking for :) Thank You Very $$anonymous$$uch :) when i reach 315 degree it will stop rotating (because its bigger then 315 and that's fine) but i also cant rotate it down because its not in range for doing rotation ! its my code :

 if($$anonymous$$yCamera.transform.rotation.eulerAngles.x <= 315 && $$anonymous$$yCamera.transform.rotation.eulerAngles.x >= 45)
 {
     print("45 - 315");
 }
 else
 {
     if(RTU == true)
     {
         print("TU :: "+$$anonymous$$yCamera.transform.rotation.eulerAngles.x);
         $$anonymous$$yCamera.transform.Rotate(-Time.deltaTime*20,0,0);
     }
     if(RTD == true)
     {
         print("TD :: "+$$anonymous$$yCamera.transform.rotation.eulerAngles.x);
         $$anonymous$$yCamera.transform.Rotate(Time.deltaTime*20,0,0);
     }
 }

how can i solve it :-?

avatar image
1

Answer by christophfranke123 · Mar 06, 2015 at 11:41 AM

You might want to use RotateTowards instea. This lets you rotate your camera toward a certain rotation without exceeding it and specify the maximum relative degree between from and to:

 camera.transform.rotation = Quaternion.RotateTowards(camera.transform.rotation, targetRotation, degreesPerSecond*Time.deltaTime);


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

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

23 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

Related Questions

Limit transform.LookAt to 90 degrees based off of object's forward axis 1 Answer

How can I set a limit to my object rotation???(Here's the code) 2 Answers

accelerometer Rotation limiting 1 Answer

How do I limit my car's z rotation when a key is pressed? 0 Answers

Limiting the rotation of an object 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