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 EZhurst · Mar 15, 2015 at 11:29 PM · rotationtransformtimescaletransform.rotationslowmotion

How would you find out if a rotation is between two values?

 {
     public bool slowMo;
 
     void Start()
     {
         slowMo = false;
     }
 
     void Update()
     {
         if (transform.rotation.z <= 40 && transform.rotation.z >= -40)
         {
             slowMo = false;
         }
         else
         {
             slowMo = true;
         }
 
         if (slowMo == true)
         {
             Time.timeScale = .3f;
         }
         else
         {
             Time.timeScale = 1;
         }
     }
 }
 

With this code I am meaning to slow down time when the rotation of the block, which this script is attached to, rotates past 40 degrees in either direction, though when I run the game it sets slowMo to true even when the block is sitting vertical. Any help would be greatly appreciated.

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

2 Replies

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

Answer by EZhurst · Mar 16, 2015 at 12:46 AM

alright, this seems to work

 {
     public bool slowMo;
 
     void Update()
     {
         Debug.Log (transform.eulerAngles.z);
         Debug.Log (slowMo);
 
         if (transform.eulerAngles.z >= 210 || transform.eulerAngles.z <= 150)
         {
             slowMo = true;
         }
 
         if (slowMo == true)
         {
             Time.timeScale = .3f;
         }
     }
 }

thank you raulrsd for your help

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
avatar image
0

Answer by raulrsd · Mar 15, 2015 at 11:33 PM

Yo have a problem with the if statement. No number could be at the same time greater than 40 and less than -40. I think that what you wanted to write was

          if (transform.rotation.z >= 40 || transform.rotation.z <= -40)
          {
              slowMo = false;
          }
          else
          {
              slowMo = true;
          }
 
Comment
Add comment · Show 9 · 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 EZhurst · Mar 15, 2015 at 11:41 PM 0
Share

that was a typo, i meant for it to be less than 40 greater than -40, but this doesn't work for me either

avatar image EZhurst · Mar 15, 2015 at 11:42 PM 0
Share

I have tried both && and || with the flipped signs and it still doesn't work

avatar image raulrsd · Mar 15, 2015 at 11:57 PM 0
Share

I guess that in editor you see that the z rotation of your object is within the desired values, don't you? Also, you could add an f at the end of the 40 and -40 to indicate the compiler that they're a float, like transform.rotation.z (just to be sure).

Additionally, could you write a Debug.Log in the update method to show what is the value of the rotation.z?

avatar image EZhurst · Mar 16, 2015 at 12:06 AM 0
Share

I had tried putting an f after the values already, that didn't change anything, and when I watched the inspector, i noticed that the box would go from 0 to 359 degrees because it wraps around so i flipped the box 180 and use >= 150 && <= 210 but got the same result.

avatar image raulrsd · Mar 16, 2015 at 12:12 AM 0
Share

And what is the rotation.z value that shows the Debug.Log?

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

Objects not rotating right half the time based on another object 0 Answers

Rigidbody rotation vs Transform rotation 4 Answers

Adding Rotation to a Gameobject 1 Answer

Rotate object around object with fixed value. 1 Answer

How to make a bone rotate facing towards a given Transform? 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