Author Topic: Sync Time of Day  (Read 60 times)

pentiumslayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Sync Time of Day
« on: November 11, 2021, 01:52:16 AM »
Would it be possible to override this to use Game Time instead of PC time?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Sync Time of Day
« Reply #1 on: November 11, 2021, 09:08:12 AM »
Hi!

What exactly do you want to achieve? Continuous rotation? (There's the AutoRotate option in the inspector).


pentiumslayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sync Time of Day
« Reply #2 on: November 12, 2021, 12:06:37 AM »
No, I'm interested in the lighting based off of my game time, not the pc time. I want the sun shining on my globe when my game time is noon, even though it's 10:00pm on my pc.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Sync Time of Day
« Reply #3 on: November 12, 2021, 09:37:12 AM »
I've extracted the internal method used by sync time of day so it can be used to align the Earth / Sun to a given date.
Next beta will include a new API as follows:

Code
	/// <summary>
        /// Sets solar rotation and adjust Earth rotation as well to match a given date
        /// </summary>
        /// <param name="date"></param>
public void SetTimeOfDay(DateTime date) {
System.DateTime Now = date.ToUniversalTime();                // Get unlocalised time
float SolarDeclination = -23.45f * Mathf.Cos((360f / 365f) * (Now.DayOfYear + 10) * Mathf.Deg2Rad);
float sunRot = ((Now.Hour * 60f) + Now.Minute + (Now.Second / 60f)) / 4f;     // Convert time into minutes, then scale to a 0-360 range value
Vector3 sunRotation = new Vector3(SolarDeclination, sunRot, 0);        // Combine the axis and calculated sun angle into a vector
_sun.transform.localRotation = Quaternion.Euler(sunRotation);
transform.rotation = Misc.QuaternionZero;
_navigationMode = NAVIGATION_MODE.CAMERA_ROTATES;
_autoRotationSpeed = 0;
}

There's also a simpler method:

Code
	/// <summary>
        /// Simpler version of SetTimeOfDay which just rotates Earth according to a 24h value
        /// </summary>
        /// <param name="time24h"></param>
public void SetTimeOfDaySimple(float time24h) {
transform.localRotation = Quaternion.Euler(23.45f, 360f * time24h / 24f, 0);
        }


pentiumslayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sync Time of Day
« Reply #4 on: November 12, 2021, 11:59:07 PM »
Awesome, thanks