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 TheGrovesy · Aug 03, 2020 at 08:42 PM · issuerotate objectvalidation

Inspector OnValidation rotation issue

I have a script 'DayNightCycle' which is attached to the main directional light which over the course of 20 minutes rotates the light to give a simple day night cycle, this works great for me.

However I wanted to be able to set the light rotation for each scene, so I added the following code:

 [Range(0.0f, 360f)]
 public int LevelStartTime = 90;

 private void OnValidate()
 {
     transform.eulerAngles = new Vector3(
         LevelStartTime,
         transform.eulerAngles.y,
         transform.eulerAngles.z
     );
 }

This gives me a 0-360 slider which allows me to set the start light rotation and see it in the editor. However when the value is slid between 90 and 270 the light keeps 'flipping' on the 'y' rotation. For example when the slider is on 177 the transform rotation value shows 3, and when its on 234 transform shows -54. However if you manually type in those same numbers in my LevelStartTime the transform correctly has the same number!

alt text

Any ideas whats going on?

annotation-2020-08-03-213755.png (20.6 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by davidcox70 · Aug 03, 2020 at 08:48 PM

Rather than set transform.eulerAngles, try;

 transform.rotation = Quaternion.Euler(LevelStartTime, transform.eulerAngles.y, transform.eulerAngles.z);

See if that works better.

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 TheGrovesy · Aug 04, 2020 at 07:42 AM 0
Share

Unfortunately this has the same issue! What is also strange is that when this 'flipping' effect happens occasionally the Y & Z axis change. Y sometimes changes to 0 and Z changes to -1.525879e-05!! Very confused about this problem. Especially as manually entering any X value always works!

avatar image davidcox70 TheGrovesy · Aug 04, 2020 at 09:08 AM 0
Share

The problem is that Euler angles do flip when "going around the back". If you are only interested in a rotation in one axis, then it should work if you do not refer to the Euler angles of the axis you are not rotating in your calculation (eg Vector3(LevelStartTime,0,0)). If you do need to set the Y and Z axis, then do this from a variable that doesn't refer back to the current rotation, as otherwise this value will flip and upset your result.

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

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

Related Questions

Issues with AnimationCurves 0 Answers

Lightmap Baking Cross-Platform: iOS vs Mac vs Windows 1 Answer

Game Froze, No Inputs 0 Answers

Cant find issue tracker's resource 0 Answers

I can't open my Unity Project 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