Forum begins after the advertisement:

 


[Part 6] How to smoothen the Sun’s movement

Home Forums Video Game Tutorial Series Creating a Farming RPG in Unity [Part 6] How to smoothen the Sun’s movement

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #18567
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi everyone, got a question on how to make the Sun movement smoother in Part 6 of our tutorial series: https://blog.terresquall.com/2021/09/creating-farming-rpg-in-unity-part-6/

    The Sun’s movement is controlled in TimeManager. Specifically, under the UpdateSunMovement() function in TimeManager:

    //Day and night cycle
    void UpdateSunMovement()
    {
        //Convert the current time to minutes
        int timeInMinutes = GameTimestamp.HoursToMinutes(timestamp.hour) + timestamp.minute;
    
        //Sun moves 15 degrees in an hour
        //.25 degrees in a minute
        //At midnight (0:00), the angle of the sun should be -90
        float sunAngle = .25f * timeInMinutes - 90;
    
        //Apply the angle to the directional light
        sunTransform.eulerAngles = new Vector3(sunAngle, 0, 0);
    }

    This function is called by Tick():

    //A tick of the in-game time
    public void Tick()
    {
        timestamp.UpdateClock();
    
        UpdateSunMovement(); 
    }

    Which is called by TimeUpdate():

    IEnumerator TimeUpdate()
    {
        while (true)
        {
            Tick();
            yield return new WaitForSeconds(1 / timeScale);
        }
    
    }

    Notice in TimeUpdate() that the frequency of the update is 1 / timeScale, which means that if you want to speed up the frequency of your time updates, you want to increase the value of Time Scale on the Time Manager component in the Inspector:

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: