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 mrapple · Feb 16, 2012 at 10:17 PM · rotationdetectdetectingdegree

Detecting a certain degree angle?

Hey, trying to figure out how to detect if a rotation is greater than 180 degrees or less than, so I can change states.

I'm coding in C# and can't really find out how to say in code

if transform.rotation = <180

or something like that, no idea how to do it. Any help would be 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
3

Answer by Berenger · Feb 16, 2012 at 10:28 PM

Rotation are done around an axis, so you need to access the good component. However, transform.rotation is a quaternion, which is a little complicated. But you can use the property eulerAngles. So, to test the rotation around the y axis :

 if( transform.rotation.eulerAngles.y = <180 ) ...
Comment
Add comment · Show 14 · 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 mrapple · Feb 16, 2012 at 10:35 PM 0
Share

Tested it, was giving me a parsing error and a unexpected symbol `<'

avatar image mpavlinsky · Feb 16, 2012 at 10:48 PM 0
Share

This seems like it would be fine, but the syntax is

if( transform.rotation.eulerAngles.y

avatar image Berenger · Feb 16, 2012 at 10:54 PM 0
Share

I admit my copy paste was a bit wild :p

avatar image mrapple · Feb 16, 2012 at 11:10 PM 0
Share

Works like a charm guys, thanks heaps for the help, I really appreciate it.

avatar image mrapple · Feb 16, 2012 at 11:14 PM 0
Share

Hmm, seems that the code works fine, but now working how I can lock to just between 2 angles, for example (Between 300 - 210 degrees) ins$$anonymous$$d of it just being greater than or less than

Show more comments
avatar image
0

Answer by mpavlinsky · Feb 16, 2012 at 10:30 PM

What are you using it for exactly? Do you want to know if something rotated 180 degrees in any combination of directions? About a single axis? Is the rotation relative to another object, like trying to detect if something is facing opposite to something else?

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 mrapple · Feb 16, 2012 at 10:36 PM 0
Share

Well, in the end, what I'm wanting to do is make a "dive" state when the player's mount is free falling through the air, once his rotation along the X is between 330 and 210, he'll change to the dive state.

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

10 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

Related Questions

Need help to detect nearby / adjacent tiles / objects whatever, without collision... HELP,Need help to detect nearby / adjacent objects to make them available for further commands. 0 Answers

I need to rotate my camera around the player by 180 degree on mouse whell click need help ! 0 Answers

Flip over an object (smooth transition) 3 Answers

Detecting the range between 2 angles 2 Answers

Detecting gameObjects in certain areas. 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