Jump to content

HOW TO: Dynamic Weather System


Trixer

Recommended Posts

Hello Everyone!

Today, I will be teaching you how to make a dynamic weather system.   We are gonna focus on creating a dynamic snow system that decides when it should snow, starts snowing, and then stops snowing when it should stop snowing.    

Disclaimer: 
There are many factors of intersect I don't know from a behind the engine point of view. I don't know what kind of AOI system that intersect implements. I do not know how pooling of events that run in a loop is handled. I do not know if there are index limits to animation sizes.  I don't know how the "wait" command in events is polled to see if  the event needs to keep waiting or not.  That being said, the way I will show you how to do this could fall apart in the long run over several months of server time due to my ignorance of the internal workings of the engine. I did how ever let it run for three hours with twenty maps stitched together and it seemed to have minimal impact on the server from a relative point of view.  It seemed each map caused the server to use about 2 more megs of ram and a bit more CPU. 

On the client the impact was noticeable but minimal. Occasionally I would loose a frame here or there, or there would be a literal 1ms freeze when the snow animation started. Be mindful that I am on a super potato 3000 running client, server, and editor + other desktop software like image editing all on the same machine. So in a deployment setting I think this would be ok.

Now that I have fully crushed all of your expectations on to the tutorial!


Step 1 - Create Snow Animation
                 -  Create a 2064 wide and 1032 high PNG.  This will make a two frame snow animation.  Each frame being 1032x1032 pixels wide

                    (yikes, goodbye mobile port!)

               

                   -  For this I just made a transparent background and scattered white dots around it. You can do something much better then me I bet. 

                      Either way I will give  you some time to invoke your creative juices.

 

                -  Open up your animation editor and make a new animation. 
                                  - Fill it in to match the picture and save (cut out in picture but loop count should be 60)


animsettings.png

 

Step 2 -  Create Global Variable

                - In your global variable editor create a new "switch variable" and call it "isSnowing" and set it false  (good naming habits are important) 

                - In global variables create a new one called "SnowRoll" set it equal to 0 

 

Step 3 -  Create the Snow Controller

                    This event will tell the world if it is snowing or note. It's the meat of the system.   

 

      -  Open up any map in your game and go to the event editor tab and create a new event on one of the tiles.

      -  Bottom left corner set the trigger to "Autorun",  don't set any sprites or anything for this event, and make sure the player can pass through it

                -  Fill the event out like the below picture 

Snow_Controller.png

      

I wont go into full details about each part of this event. I think it is pretty straight forward. It checks every minute to see if snow should start or stop and sets the "isSnowing" switch to true or false.     In the above script there is a 30% chance it will start snowing and a 50% chance it will stop snowing every minute.  This works great for view purposes but is way to high for a real production kinda thing.  The conditional statement that checks to see if our "SnowRoll" variable is above a specific number can be changed to increase or decrease the snow starting and stopping chance.   For something a little more realistic you should set the first one to be  greater then 95, and the second one can stay the way it is. 

If you want to create various weather types or bios, you will need to expand this event to allow for more weather, to set more switches like "isRaining" or whatever. you can experiment here. 

 

Step 4 - Showing the snow in the world

        - Time to put that snowing animation to the test and show the snow in the world!

           This isn't to hard but can be tedious if you have a lot of maps that you need it to snow on.

           (Still less work then what adding weather to the source code might take when I do that, so still not bad!)

         - For each map you want it to snow on find you any tile and create an event on that tile. 
         - Set it like before, Autorun trigger, no sprites, no collision, the player shouldn't even know it is there. 

         - Fill it out to match the picture below 
Snow_Animator.png

 

    - VERY IMPORTANT!!!!!!!!!!!

          - In the play animation command. You need to set it to the map that you put this event in. At x15 y13 coordinates!!!!!

 

          - You must create this event in every map you want it to snow in! 

 

 

5 - Save and restart everything! 

 

That is it!  You should have snow that comes and goes on your maps in a some what random interval. There is a lot to do with this system to make it look production ready!  You can adjust size of snow animation and where it is played in the map to get it to line up better with the maps surrounding it. 

The way the system works is there is always a chance that it might appear to be snowing for a player but the "isSnowing" flag is set to false. Keep this in mind when setting up events or things that work off the weather system. Almost all players will see it to be snowing for a tad bit longer then the system will think its snowing for. This is because animations have to finish playing and I can't find a way to just stop them.  This at the end of the day isn't that big of a deal and will most def get you by until source launch!

I am extremely interested in hearing about peoples experiences with performance using this method. I decided to go with this method instead of creating a snowing animation over the player and moving it with the player because I fee like in a real game setting with lots of players  it would be less resources to animate the snow on the map instead of personally for each player.  (However creating an animation that follows the player around and slightly overlaps the camera view might make for a cleaner looking effect between maps)

If you guys liked this tutorial let me know by posting a reply to the thread, liking, and subscribing to my profile!

My next tutorial in a couple days will either be player grown crops or player owned houses. You guys let me know below what you would like to see! 

 

Link to comment
Share on other sites

9 minutes ago, Kasplant said:

Hahah I like it, but B5 will have a weather system in the engine. 

 

Doh! 

 

Oh well! I am glad it will cause this is a system that should come from the engine and not come from events!

 

Oh well! 

 

 

Link to comment
Share on other sites

Very nice tutorial. As Kasplant said, we'll get a weather system on b5, but we can use this while b5 isn't released, so I think this is a very nice contribution anyways.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...