Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Hirnfroster · Oct 20, 2016 at 01:16 PM · rotationtransformangle

Natural rotation of sun and moon with 2 axis

Hi guys :)! I hope you can help me with a rotation problem.

Lets lay down my facts: I'm modelling a day/night cycle and I didn't want the sun and the moon just go directly over your head... If we take a look at the real life, the day night cycle is basically about two rotations. (Just let us assume the sun circles the earth ;))

  1. The Y-axis. The rotation of this axis determines the time. This is my reference point to the ingame time.

  2. The Z-Axis. This basically determines the angle of the sun or the moon.

In my project I attached the sun and the moon to an empty gameobject. Lets call it "Time-Pivot". Sun and moon are facing that Time-Pivot and are on the opposite site of each other.

I also really want to add the feature that I can choose some settings for the cycle to simulate a polarnight or polarday. For this reason I added 3 custom floats.

 1. MaxAngle
     This is the maximal angle of the sun and the minimal angle of the moon.
 2. RisingAngle
     At this angle I defined that the sun is rising/setting. This doesn't has to be 0. Since on the polarday the sun actually passes that point where it would set, but it doesn't, because the risingAngle is > 0.
 3.  MinAngle
     This is the lowest angle of the sun and the highest angle of the moon. In most cases it should be less then 0, then the sun is under the horizon.

I also added two other settings.

 1. RisingTime
     This is the time (in ticks*), when the sun reaches the risingAngle)
 2. SunsetTime
     This is the time (in ticks), when the sun reaches the rising Angle again.
 So I can choose at which time I have the sunset and the sunrise.

*My ingame time is calculated through the rotation of the time-pivot for the Y-axis. So basically, if the Y-rotation of the time-pivot is 180°, it is 12:00. I have 3600 ticks and one tick is one second.

Now comes the problem: I managed to do the rotation around the Y-axis with Transform.Rotate(0, 0.1f, 0); So I have 1 tick per second. This is only the Y-rotation. I have no idea how to implement the rotation of the Z-axis (the height of the sun). I thought about something like smoothstep, but I can't manipulate the rotation, because it is already depending on that Transform.Rotate() thing... It is about applying two roationspeeds at the same time, but one rotation varys quite a lot.

  • already have functions that can calculate the angle of the Z-axis depending on the time. You may refer it to something like sunAngle(ticks) <- mathematic function. But it returns the angle of the Z-Axis in Degrees. I can calculate the answer but not set it :/

P.S.: I'm not that experienced yet... If you have a better idea on how to implement the cycle in a good and natural way, you can present your idea instead :)

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
0
Best Answer

Answer by Hirnfroster · Dec 16, 2016 at 01:40 PM

After some further research and lots of practice, I could figure out how to do it: The whole thing doesn't rotate anymore, but rather sun and moon independent (Some more option are allowed due to this new system) . The Rotation of the sun (which determines the Time) is now World space and the rotation along the x-axis, which determines the height is now done with the following line of code:

sun.transform.localEulerAngles = new Vector3(SunAngle(), sun.transform.localEulerAngles.y, sun.transform.localEulerAngles.z);

where SunAngle() is the function to calculate the actual height. Basically just the x-rotation is overriden. If you still have a better solution let me know :D

Comment
Add comment · 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
0

Answer by Zodiarc · Oct 20, 2016 at 01:47 PM

Actually there's an asset in the asset store for this called uSky Pro https://www.assetstore.unity3d.com/en/#!/content/24830 It as a realistic mode where you can setup the longitude, latitude and height above the sea level.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I multiply the rotation of a mirrored object? 1 Answer

Problem with Quaternion.Euler() when rotating object 3 Answers

Limiting a GameObject Rotation 1 Answer

Unity - Decrease/Increase the "Z axis" angle axis on Update() 0 Answers

Animating in Unity Rotation snaps to last rotation key 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