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 thenachotech1113 · Dec 31, 2013 at 11:35 PM · rotationrotate objectpercentage

a variable that when an object is tilted 0º = 0 and 90º = 1

sounds simple, i know the math to do that. divide the rotation by 90 and you get it. anyway there is one problem with this: if the object tilts, for example, 15º on the x axis it would work, but if it tilts 15º in the oposite direction on the same axis the rotation will be something like 375º, and dividing this by 90 will certainly give me a number over 1. i need a way for it to give me a number between 0 and 1 regardless on the direction it tilts. and i certainly dont know how to do that math. ill keep on trying to achieve it but certainly a hand would be much apreciated. thanks to all.

p.s. if i was not clear on my explanation, which i probably wasnt, feel free to coment me or edit the post if u think there is a better way to explain it. thanks a lot for all your help, and happy new year.

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 tanoshimi · Jan 01, 2014 at 12:23 AM 0
Share

So what do you want to return for an angle of 180' or 270'?

avatar image mescalin · Jan 01, 2014 at 01:00 AM 0
Share

that's sine isn't it?

$$anonymous$$ath.sin

assu$$anonymous$$g you want a smooth oscillation, sin90 is 1, sin0 is 0, the other answers provide a more linear output

avatar image thenachotech1113 · Jan 01, 2014 at 09:54 PM 0
Share

you are right, i think i will use that. it is briliant and simple. happy 2014

avatar image mescalin · Jan 02, 2014 at 02:57 AM 0
Share

happy new year and good luck with your code

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ArkaneX · Jan 01, 2014 at 12:38 AM

I guess the easiest option is just checking if your rotation for a given axis is greater than 180 and in this case subtracting it from 360. C# sample for x axis:

 float rotation = transform.eulerAngles.x;
 if (rotation > 180f)
 {
     rotation = 360f - rotation;
 }
 float tilt = rotation / 90f;

This sample will return values over 1 for rotation greater than 90 and lower than 270, but you can tune the sample to take this into consideration. Or if such angles are impossible in your case, then you can leave the sample as it is.

Comment
Add comment · Show 2 · 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 thenachotech1113 · Jan 01, 2014 at 09:44 PM 0
Share

thanks dude, i had thought of using if satatements, though not in this way. now it seems realy simple. thanks a lot again and happy 2014

avatar image ArkaneX · Jan 01, 2014 at 09:47 PM 0
Share

And for you as well :)

avatar image
1

Answer by HappyMoo · Jan 01, 2014 at 12:52 AM

 float magicNumber = (180-((angle+180)%360))/90;

Now this gives -1 to 1 (for -90 to +90) in case you also want to know the direction. If you don't care about direction, slap a Mathf.Abs() around the formula.

Comment
Add comment · Show 3 · 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 thenachotech1113 · Jan 01, 2014 at 09:45 PM 1
Share

thanks dude,happy 2014

avatar image HappyMoo · Jan 01, 2014 at 09:48 PM 0
Share

You need to accept the answer. Happy 2014 to you too

avatar image HappyMoo · Jan 03, 2014 at 10:48 PM 0
Share

Would you $$anonymous$$d accepting the answer?

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

22 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

Related Questions

Rotate object based on another rotation above a certain threshhold 1 Answer

gameobject stops moving correctly when rotating 1 Answer

Smooth rotation about global axis instead of local axis. 1 Answer

The object turn but the axis dont (SOLVED) 3 Answers

I need Some Info About Rotation And Pvot 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