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 /
avatar image
0
Question by meleejohn · Feb 24, 2018 at 11:43 PM · rotationif-statementseuleranglesangles

Problem when checking a Quaternion Eulerangle axis

So, as shown in the code attached below I am having a problem checking the Z axis of my gameobject. The odd part is that it's just the line: "CameraBody.transform.eulerAngles.z <= rotation2 " at the bottom, that would be line #52. If I take that away and just check the boolean then the if statement goes off. But it seems for some reason that the addition of checking the angle doesn't work. So for example Rotation 2 is set at -50 and the cameraBody is rotating towards negative along the Z-axis. Once the Camera passes -50 and continues lower into the negatives the if statement doesn't go off. But upon switching the switch statement case to "greater than" so that line #39, the if statement will go off just fine. Any ideas or any already answered questions would be appreciated. Thank you!

 void Update () {
     QuestionMark ();
     if (detectingPlayer == false && detectedplayer == false) {

         switch (Operator1) {
         case ">":
             if (ReverseRotation == false && cameraBody.transform.eulerAngles.z >= rotation1) {
                 cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, 0.2f);
                 //Debug.Log ("Positive Rotation 1");
             } else if(ReverseRotation != true) {
                 Debug.Log ("Making reverse rotation true #1");
                 ReverseRotation = true;
             }

             if(ReverseRotation == true) {
                 //ReverseRotation = true;
                 cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, -0.2f);
                 //Debug.Log ("Negative Rotation 1");
             }
             break;

         case "<":
             if (ReverseRotation == false && cameraBody.transform.eulerAngles.z <= rotation1) {
                 cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, 0.2f);
                 //Debug.Log ("Positive Rotation 2");
             } else  if(ReverseRotation != true) {
                 Debug.Log ("Making reverse rotation true #2");
                 ReverseRotation = true;
             }

             if(ReverseRotation == true) {
                 //ReverseRotation = true;
                 cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, -0.2f);
                 //Debug.Log ("Negative Rotation 1");
             }
             break;
         }

         switch (Operator2) {
         case ">":
             //Debug.Log ("In greater than, Operator 2 A");
             if (cameraBody.transform.eulerAngles.z >= rotation2 && ReverseRotation == true) {
                 ReverseRotation = false;
                 //cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, -0.4f);
                 Debug.Log ("Reverse Rotation = false 3");
             }
             break;

         case "<":                
             Debug.Log ("In less than, Operator 2 B");
             Debug.Log ("Reverse rotation is: " + ReverseRotation);
             //Debug.Log ("Rotation 2 is: " + rotation2);
             if (cameraBody.transform.eulerAngles.z <= rotation2 && ReverseRotation == true) {
                 ReverseRotation = false;
                 //cameraBody.transform.localRotation *= Quaternion.Euler (0, 0, -0.4f);
                 Debug.Log ("Reverse Rotation = false 4");
             }
             break;
         }

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
1
Best Answer

Answer by ElijahShadbolt · Feb 25, 2018 at 02:01 AM

An answer from this question may be of help. Euler angles are stored as values (in degrees) from 0 to 360, not -180 to 180. Instead of comparing it to -50, maybe try 310 ? You would also have to check two ranges: 0 to 50 and 310 to 360, instead of just -50 to 50.

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 meleejohn · Feb 25, 2018 at 05:42 PM 0
Share

Thank you very much for that link to someone else's solution, it's exactly what I needed! Also, thank you for that information on Euler Angles, i never knew that it was only 0 to 360. I'll keep that in $$anonymous$$d next time I mess around with Euler Angles!

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

104 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

Related Questions

Instantiating an object in front of the player 3 Answers

Continuously rotating by 90 doesn't get me the initial angle 0 Answers

Rotation losing precision 0 Answers

Whats the Difference Between Rotation EulerAngles and Quaternions? 2 Answers

How can I store the individual values of EulerAngles on a Database then re-apply 2 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