So I’ve been trying to create a script that would take the current time, convert it to seconds, and take the current day with an algorithm to get the accurate sunset for that day, and set the x value of the directional sunlight to the corresponding output.
What’s appearing to happen is that whenever Rotation
> 90, the light y value jitters between Rotation
and 180 - Rotation
Here’s the code that I have currently
public float Time;
public int Day;
public float Slope;
public float Intercept;
public float Rotation;
private void Update() {
string daySetting = functions.GetSetting("gameTime").SettingData;
Debug.Log("setting = " + daySetting);
if (daySetting == "worldTime") {
//Commented out for testing purposes, this IS part of the final script
//Time = (System.DateTime.Now.Hour * 3600) + (System.DateTime.Now.Minute * 60) + (System.DateTime.Now.Second);
Day = System.DateTime.Now.DayOfYear;
// y = -81.5 | x - 265 | + 64800
float sunset = -81.5f * Mathf.Abs(Day - 265) + 64800;
//Calculating Equation
Slope = 0.0f;
Intercept = 0.0f;
Slope = 180 / (sunset - 21600);
Intercept = -1 * 21600 * Slope;
Rotation = (Slope * Time) + Intercept;
transform.rotation = Quaternion.Euler(Rotation, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
}
}
I don’t know what’s going on, or what might cause this, but any and all help on why this may be happening, or code that would help fix this issue is greatly appreciated.