Forum rules - please read before posting.

morning - afternoon - evening

Much of the documentation is clear and easy to apply. An idea arose how to implement in the game (morning - afternoon - evening) for example a level of light in the rooms and it depends on (morning - afternoon - evening) will vary in intensity. In other words, there are 5-10 light sources, and depending on (morning - afternoon - evening) I want them all to change the brightness / intensity, advise how to do it right?

Comments

  • You need to write a custom script. You can access the global variable you use to store the in-game time with AC.GlobalVariables.GetIntegerValue(x) (where x is the number of the variable you want to get). Then it should just be a matter of interpolating between two values and changing the light intensity as desired.

    This is actually a simple project that can get you started learning C# and Unity. You just need to learn how to declare variables and game objects, how to change an object's component values via code, and if-statements. Then you just need simple middle-school maths (or Unity's own Lerp function) to figure out the relationship between your time variable and the light intensity.

  • A Global Variable to record the game's current "time of day" will be necessary, but if you're just looking to do something as simple as changing the light's intenstity based on its value, then you can rely on animation rather than scripting.

    AC's Link Variable To Animator component can be used to synchronise an Animator's Float, Int, or Bool parameter with an AC Global variable of the same type.

    If you had an Integer parameter named "Daytime", where 0 = morning, 1 = afternoon, 2 = evening, you could use this component to link this Variable to a "Daytime" integer parameter in an Animator. That Animator could then be used to control the intensity of your lights based on this value.

  • Thanks a lot! Animator is a good idea.

  • I must correct myself: currently, the Link Variable To Animator only connects to Component Variables.

    I will add the ability to connect it to Global Variables in the next update.

    In the meantime, you can attach a simple script to your Animator to connect with a Global Variable:

    using UnityEngine;
    
    public class TimeOfDayAnimator : MonoBehaviour
    {
    
        public Animator myAnimator;
        public string variableName = "Time of day";
    
        void Update ()
        {
            myAnimator.SetInteger (variableName, AC.GlobalVariables.GetVariable (variableName).IntegerValue);
        }
    
    }
    

    If you're using a Float, change "Integer" to "Float".

  • How often do you have updates? Once a month or once every 2 months?

  • edited November 2022

    There's no set rule, but the next release is planned for mid-December.

  • https://streamable.com/58sfym
    I created light bulbs for all light sources and created 4 states morning-day-evening-night, tell me how to use them correctly based on the time of day that you described above?

    Or is this not how it is done at all, I'm trying to figure out how to do it right ....

  • Create your four states as separate animations, i.e. Morning, Day, Evening, Night.

    Then set up your Animator Controller to transition between them based on a parameter value. The script above can then be used to sync this parameter value with a Global Variable.

    What type of variable are you using, and what values does it have for each of the 4 states?

  • edited January 27

    https://streamable.com/hfg7gv
    Created 4 states morning - afternoon - evening - night

    By analogy as in RPG-Maker (after studying AC + Unity, RPG-Maker seems to me now primitive and limited)

    Tell me what is the next step so that the AU can control the animator and switch the states itself? For example, my UI will display morning - afternoon - evening - night (4 numbers) and when a character visits 2 rooms, the state changes, for example from morning > day. Probably needs to be done (8 numbers, 2 numbers per state) and when moving from room to room, add the value +1

  • Another option would be to create 4 "still" animations (a couple of frames with the same light settings, without any transitions, one for each time of day). Then you would create a single animation state in the animator controller ("Day/Night Cycle"), and instead of assigning an animation to it, you would right click on it and create a new blend tree.

    Then you'd open the blend tree, select 1D as the Blend Type, and choose your "time" integer parameter. This is my own Blend Tree for a character's Walk animation:

    In this case, the parameter represents the angle the character is facing, and the blend tree will interpolate the animations if the angle falls between the threshold values.

    In your case, the parameter would represent the time of the day, and you could set the thresholds like this:

    0 - Night

    1000 - Night

    1200 - Sunrise

    1400 - Day

    3000 - Day

    3200 - Sunset

    3400 - Night

    4000 - Night

    Meaning that between 0 and 1000, only the "Night" animation would set the lights. Between 1000 and 1200, a mix of "Night" and "Sunrise" would colour the scene. At exactly 1200, only "Sunrise" would colour it. Then between 1200 and 1400, the blend tree would slowly blend the colours between "Sunrise" and "Day", etc.

    If you create a one-way link between the "time" global variable and the "time" animator parameter, then any variable change will be automatically reflected on the blending of the animations above.

  • edited January 29


    Created like this, but how to make time move from variables?

  • Use the script above, but rename Integer to Float.

    Also, rename your "Time-of-Day" Animator parameter to match the name of your variable, "Time of day.

  • https://streamable.com/kzfeu3
    I created an animation in which the night is from 0 to 6 in the morning, from 6 in the morning to 12 is the day and from 12 in the afternoon to 18 is the evening, and from 18 to 24 is the night. Tell me, based on the video, why does the animation switch not smoothly but abruptly, although in the animator it flows smoothly mixing two animations and sometimes even three?

  • I meant something like this:

    From your video, I'm not sure exactly how you are changing the scene's colours, but your animations seem to be toggling different post-processing effects on and off instead of changing the lights directly, correct? That should be the reason the changes are abrupt (you can't blend two binary states, no such thing as "half on" or "half off"). I advised you to use blend trees because previously the animations were manipulating the colour and intensity of lights, which can be blended.

  • Good answer. It is a pity that you have to abandon the post effects with them looks very nice.

  • edited January 31

    Rairun

    From your video, I'm not sure exactly how you are changing the scene's colours, but your animations seem to be toggling different post-processing effects on and off instead of changing the lights directly, correct? That should be the reason the changes are abrupt (you can't blend two binary states, no such thing as "half on" or "half off"). I advised you to use blend trees because previously the animations were manipulating the colour and intensity of lights, which can be blended.

    https://streamable.com/ox3eal

    There are many kind people in the world who advised how to create animations correctly. Here is an example that works great.

    ChrisIceBox

    using UnityEngine;
    
    public class TimeOfDayAnimator : MonoBehaviour
    {
    
        public Animator myAnimator;
        public string variableName = "Time-of-Day";
    
        void Update ()
        {
            myAnimator.SetFloat (variableName, AC.GlobalVariables.GetVariable (variableName).FloatValue);
        }
    
    }
    

    Chris, could you fix the script so that after 24 hours it goes to 0 hours and not to 25?

  • Glad you got the effects blending!

    The script that Chris provided you only serves to copy the variable over to the animator parameter, but other than that, it doesn't have anything to do with the way you choose to keep track of time in your game.

    An easy way to keep time in your game is to create a looping actionlist that runs in the background, like this: wait 1 second -> add 0.1 (or a different number, it depends on how long you want your day to be) to the Time-of-Day global variable -> (Link this back to the first wait action).

    Once you've got this running then you can introduce an extra action after adding 0.1 to the variable. This action would be for checking the global variable to see if it's 24 or higher. If true, set the global variable to 0 and only then loop back to the first wait action. If false, go straight back to the wait action.

    This is if you want a running clock. If the time of day is changed by in-game events instead of time spent in game, then you can just use a Set Variable action to change the time instantly (this will look abrupt). If you want a smooth fast transition from the current time to the desired time, you can use a similar loop to the one above with a much shorter wait time (i.e. 0.02s) and break the loop when the variable reaches the desired time.

  • The easiest way to increase and loop a variable's value over time is to use a dedicated Timer - a new feature introduced in AC v1.76.1.

    Timers can be defined from the Timers Editor, found in the top toolbar under Adventure Creator -> Editors -> Timers Editor.

    Create a Timer that ranges from 0 to 23, have it run on a loop, and link it to your "Time of day" float variable:

    To run the Timer, call the Variable: Set Timer Action.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.