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 Arm1y · Feb 09, 2014 at 05:42 PM · transformrotatesunxdaynight

Sun(light) rotation is not working

Hello, I am trying to set rotation of Sun on the script(game) start. It is based on System.DateTime. All is all right, but rotation is still different(wrong) by my variables.

So here is code:

     var sun : Transform;
     var dayTime : float;    
     
     if(System.DateTime.Now.Hour >= 5 && System.DateTime.Now.Hour <= 19) //15 hours
     { 
         dayTime = ((System.DateTime.Now.Hour-4)*3600+System.DateTime.Now.Minute*60+System.DateTime.Now.Second);
         sun.transform.Rotate(dayTime/300, 0, 0);
         Debug.Log(dayTime/300);
     }

In game rotation of sun is something like X: 327,Y: 180, Z: 180. But i really dont get it, what is wrong with it? But it have to be something like X: 163, Y: 0, Z: 0. If you want more info, just write what you need. Thanks for answers and help.

Edit: Can it be anything like gimbal lock - http://en.wikipedia.org/wiki/Gimbal_lock i really dont know?

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 Kiloblargh · Feb 09, 2014 at 06:38 PM

Instead of using transform.Rotate, try setting transform.EulerAngles directly with a single Vector3.

Comment
Add comment · Show 4 · 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 Arm1y · Feb 09, 2014 at 06:58 PM 0
Share

I tried to change it and still not working, same situation :/. When i want to rotate sun over time it's working perfect, but i need to set rotation only time, when game start, and it's not working.

avatar image Kiloblargh · Feb 09, 2014 at 08:34 PM 0
Share

Create 4 rotations called $$anonymous$$orning, Noon, Evening, and $$anonymous$$idnight, deter$$anonymous$$e which two your current dayTime is between, and use Quaternion.Slerp to interpolate between them.

avatar image Arm1y · Feb 09, 2014 at 09:27 PM 0
Share

I need to set rotation of X axis of sun object just only and once time, when game starts(just instantly rotate it), so something like:

 transform.rotation = Quaternion.AngleAxis(180, Vector3.left);

for example, but it is still not working :/.

avatar image Kiloblargh · Feb 10, 2014 at 06:40 AM 0
Share

Sorry, that (4 sun position variables, Slerp between 2) was my most foolproof idea. If you tried that approach and it didn't work, then I just don't know. Your dateTime math must not be right.

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

18 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

Related Questions

if(transform.Rotate) Doesn't Work? 4 Answers

i want an object rotate 45 degrees more than an other one 1 Answer

Avatar Rotation Control [UnityScript] 0 Answers

how can i target a nother cube from a script 1 Answer

Orientation Vs. Rotation: How do I specify more than 360deg rotation for a quaternion, in the editor? 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