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 GameSlayerGS · Apr 22, 2013 at 07:07 PM · rotationrotateifdegrees

Problem with "if or" statement.

I have a small and simple script that makes something spin, well I got it to spin, my problem now is getting it to spin and stop at a certain rotation in degrees. Currently it spins as long as the rotation value is > or < the target (depending on which direction it's spinning) however, that doesn't work nicely if it's at 0, in which case I can't have it spin one direction due to it not > the target number. So I added a "|| rotation1 == 0" so that way it would spin even if it were 0, but now it stops when it's not 0. What am I doing wrong here?

  function Activate (end, direction) {
    if (end == 1 && direction == 1) {
        if (rotation1 > 90 || rotation1 == 0) {
            Spin(1);
        }
    }
}
 

Comment
Add comment · Show 4
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 AlucardJay · Apr 22, 2013 at 07:19 PM 0
Share

What is rotation1 ?

 if (end == 1 && direction == 1) {
     Debug.Log( "rotation1 = " + rotation1 );
     if (rotation1 > 90 || rotation1 == 0) {
avatar image GameSlayerGS · Apr 29, 2013 at 02:07 PM 0
Share

rotation1 is the current rotation value for the spinning object. The combination of "end" and "direction" indicate a combination of rotation1's goal (what it should stop at when it gets to) and "Spin" which indicates the direction (left or right) to rotate. Again, the problem is that my OR statement indicates to spin if it's equal to 0 or greater than 90, but it stops after no longer being equal to 0.

avatar image DaveA · Apr 29, 2013 at 02:33 PM 0
Share

If it's 0, it will spin a little. Let's say it spins to 0.01. Now it's not 0 and it's not > 90. I think you will find this helpful: http://wiki.unity3d.com/index.php/Angle

avatar image GameSlayerGS · May 08, 2013 at 03:29 PM 0
Share

Thanks! I do find that helpful. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vonni · May 08, 2013 at 06:39 PM

I had the same problems trying to position and rotate things over time and used if statements all over the place, but it simply doesnt work well.

Use Mathf.Lerp (Read up on this) to do presision positioning/rotating that have start and end positions at some point

Or Something using the link DaveA posted.

Sidenote Lets say you rotate a ball around and want it to stop at 50 degree rotation, Doing if(degree == 50) will pretty much never work as its value will almost always be 49.2044, 49.7094, 50.1235 etc. and > 50 will not give you accurate rotations.

Also remember that as soon as the euler goes over 360 its starts back at 0.

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

14 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

Related Questions

Rotation: rotate by a defined angle 1 Answer

Rotate object in 45 degree steps 1 Answer

How can I rotate an object with certain degrees? 2 Answers

What is the most efficient way to rotate an object? 3 Answers

Detecting the range between 2 angles 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