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 hawken-2 · Apr 25, 2012 at 09:11 AM · quaternionrotatearoundlocaleulerangles

is there any way to get a sane number on an objects current y rotation?

Want to build a clock, rotate a plane, how can I see when the plane is rotated 0, 90, 180, 270 degrees etc? (I would like to read these rotation states then do other actions and so on)

All I get is a snapping from 90 to 270 in the readout. Or worse.

Is there any sane way to do this without descending into madness?

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 GuyTidhar · Apr 25, 2012 at 09:44 AM 0
Share

are you using c# or js?

avatar image hawken-2 · Apr 25, 2012 at 09:55 AM 0
Share

JS but I'm sure I could translate the C# cheers,

avatar image GuyTidhar · Apr 25, 2012 at 10:05 AM 0
Share

Do you need to know when it is at 0,90,180 and 270 or when it was rotated from its initial rotation by 0,90,180,270...?

avatar image hawken-2 · Apr 25, 2012 at 10:06 AM 0
Share

ah from the initial rotation cheers

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GuyTidhar · Apr 25, 2012 at 10:17 AM

I think this should do the trick:

 var previousSection : int;
 var baseY : float;
 var currentY : float;

 function Awake()
 {
     baseY = transform.eulerAngles.y;
     previousSection = Mathf.RoundToInt(transform.eulerAngles.y - baseY) / 90;
 }
 
 function Update()
 {
     currentSection = Mathf.RoundToInt(transform.eulerAngles.y - baseY) / 90;
     if ( currentSection != previousSection )
     {
         previousSection = currentSection;
         Debug.Log("New Section! = " + currentSection);
     }
 }
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 aldonaletto · Apr 25, 2012 at 11:34 AM 0
Share

You should round the result of the division, not eulerAngles.y:

   $$anonymous$$athf.RoundToInt((transform.eulerAngles.y - baseY) / 90)

This will center the values around 0, 90, 180 and 270, giving about +/- 45 degrees margin around each angle.

avatar image
0

Answer by hawken-2 · Apr 25, 2012 at 10:26 AM

not working for me entirely, seems to dump 0 & 3 then 2 & 1 at the same time in the debug. I added the following:

 var previousSection : int;
 **var currentSection : int;**
 var baseY : float;
 var currentY : float;
 
 function Awake()
 {
     baseY = transform.eulerAngles.y;
     previousSection = Mathf.RoundToInt(transform.eulerAngles.y - baseY) / 90;
 }
 
 function Update()
 {
     **transform.Rotate(0, -1, 0);**
     currentSection = Mathf.RoundToInt(transform.eulerAngles.y - baseY) / 90;
     if ( currentSection != previousSection )
     {
        previousSection = currentSection;
        Debug.Log("New Section! = " + currentSection);
     }
 }
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 GuyTidhar · Apr 25, 2012 at 12:49 PM 0
Share

So its working now?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Ball Rolling Animation Not Working Properly 0 Answers

Fixing the rotation around a particular axis using Quaternions? 2 Answers

Circling around a target while maintaining direction of facing 0 Answers

Rotating Camera Around Central Point Using Arrow Keys 1 Answer

Convert Quaternion to Eulerangles 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