Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[RELEASED] Terrain Engine 2D - A 2D Block Engine Sandbox

Discussion in 'Assets and Asset Store' started by mattwilson180, May 23, 2018.

  1. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    Terrain Engine 2D
    A Complete 2D Block Engine for Unity

    Asset Store - Website - Documentation -
    Demo
    Checkout the Discord!
    General
    Terrain Engine 2D provides everything you need to generate and modify a complex 2d sandbox world. Simply setup all your tilesets within the Custom Inspector, code your terrain with the Procedural Generation Framework, and hit play to have your own destructible sandbox world created in minutes! Complete with advanced Fluid Simulation, Block Lighting, and Dynamic Colliders.

    Screenshot3.png
    Features
    Terrain Engine 2D is packed with features and much more is on the way! Checkout all the features in depth in the video below!



    Grid Base Tiling System
    The world in Terrain Engine 2D is made up of hundreds of thousands of tiles, where tiles are components of the different kinds of blocks which make up the terrain. The world is made up of multiple layers of blocks, each layer has a grid coordinate system which is used to index every single block in that layer.
    Chunk Loaded Mesh Rendering: The terrain is rendered in chunks of blocks using Meshes allowing for only portions of the world to be loaded into the scene at once.


    Z-ordered Layering: Every different block type and layer is placed on a different z position to determine their render order.


    Bitmasking: Bitmasking is used to texture the tiles to determine which edges and corners of each block to render.


    Multi-tile Blocks: Multi-tile blocks are supported


    Block Variations: Multiple Block Variations are supported


    Procedural Map Generation Framework

    The terrain is generated by iterating over every grid coordinate in the world and running through a set of rules determined by the developer. In the simplest form, these rules are used to determine if a block is placed in that grid coordinate. The engine contains a framework to help the developer write the code to procedurally generate the terrain in this fashion. The framework contains a number of helper functions to make the process much easier, but does not restrict the developer in any way. These functions allow the
    developer to easily write out the rules used to generate their terrain.
    • Simple and easy to setup
    • Supports multiple passes over the grid
    • Use your own noise algorithms and random functions
    • Helper Functions:
      • Randomly add or remove blocks from any layer based on probability
      • Use Perlin Noise to determine where blocks are placed
      • Add or remove fluid from a block
      • Create pools of water
      • And more...
    Dynamic Modification Tools
    The engine contains a few tools to help you modify the world dynamically. The On Screen Display (OSD) and Grid Selector work hand in hand to allow you to completely reshape your generated world at runtime. The OSD gives access to all of the layers and blocks used to generate the terrain, allowing you to add or remove any kind of block from the terrain. Where as the Grid Selector conveniently shows you the area of the terrain in which you are modifying.
    • Static World Modification class for easy dynamic world modification through code​
    • Example Input Handler for controlling user input​
    • OSD
      • Toggle Lighting​
      • Toggle Build or Destroy​
      • Adjust the modifying radius​
      • Select multiple layers for destruction​
      • Access to all block types for building​
      • Hide individual layers​
      • Save the world to file​
      • See the number of currently loaded blocks and chunks​
      • FPS counter​
      • Display for the current selected blocks in each layer​

    • Grid Selector
      • Snaps to grid
      • Shows the current selected block/area
      • Shows an image of the block to be placed with proper render order (z position)
    Place and destroy blocks by layer

    Elegant block placement/destruction

    Full Collider System
    The engine comes complete with a full collider system for the terrain. The collider system uses Unity's own 2d colliders to allow for complete compatibility with Unity's own physics system. Each chunk of terrain has its own PolygonCollider2D, where the paths/points are set using a fast custom path/edge finding algorithm.

    • Optimized to minimize the number of collider paths and points.
    • Paths are dynamically updated as terrain is modified.
    • Colliders are set based on block layers, allowing for multiple layers to have colliders
    • Procedural PolygonCollider2D point setting algorithm

    Complete Fluid System

    Terrain Engine 2D comes fully equipped with a fast and beautiful fluid simulation. Allowing for both top-down and side-scroller style fluid flow. Fluid can be procedurally generated, added and removed at runtime, and flows based on a specified block layer. Take full control over the simulation by modifying the physics properties in the inspector.

    • Cellular Automata: Fluid flows by iterating over all the loaded fluid blocks
    • Fluid Physics: Well rounded fluid physics allow for a beautiful and smooth simulation
    • Optimized: The simulation if heavily optimized to perform fast and smooth under any situation
    • Custom Fluid Colors: Modify the color of the fluid to your liking. Controlled by the fluid pressure
    • Dynamic Fluid Pressure: Each fluid block can become pressurized allowing them to hold more fluid than the maximum, allowing for upward rising fluid

    Basic Block Lighting
    Currently the engine comes with the most basic form of block lighting, allowing terrain to be hidden from the view of the player. When lighting is enabled, a shadow mask will be generated based on the blocks of a selected layer.

    A full lighting solution is currently under development, more information can be found under the Roadmap section.
    • Fast shadow masking
    • Control how many blocks are illuminated from the edge of the terrain
    • Set the opacity of the shadow mask
    • Dynamically updated as terrain is modified

    Custom Inspector
    The World has a very comprehensive custom inspector allow easy access to all the properties you as a developer might want to modify. Everything from adding the textures for the blocks, to setting the world size can all be done inside the World Custom Inspector. No need to jump back and forth between multiple GameObjects, or search through scripts. Below you can see all of the different properties you have easy access to.
    Screenshot11.png

    One of the biggest components is the ability to setup all the blocks and layers directly within the World Custom Inspector. Within the inspector there is a Block Setup tab containing a number of reorderable lists. Each list allows you to add, remove, and reorder all the elements in that list. There is one master list which holds all of the layers, and for each layer there is a separate list for all of the blocks in that layer.

    • Layers
      • Name: The name of that layer
      • Colliders: Whether that layer will have colliders generated along the edge of its blocks
      • Tileset Material: The material used to generate the layer mesh. It contains all the textures of every block type in that layer
    • Blocks
      • Name: The name of that block
      • Overlap Block: Whether that block is an Overlap Block. This is a special type of block which overlaps surrounding blocks for easy tile blending.
      • Variations: The number of variations of that block's texture
      • Texture Width: The width of the block's texture (in tiles) in the tileset
      • Texture Height: The height of the block's texture (in tiles) in the tileset
      • Texture Position: The position of the block's texture (in tiles) in the tileset

    File Saving and Loading
    The most recent addition to the engine is the ability to now load and save the generate terrain to file. This allows you to save any changes made to the terrain in game, and then reload that world in consecutive plays. Only the most significant data is saved to ensure fast serialization. Worlds are saved in two files; one file to save the world's name, size, and seed, and another to save all the block data.

    The engine contains a static serialization class allowing you to easily save or load the world from within the code. World's can also be loaded right from the World Custom Inspector, with options for saving the generated world on start. While in play mode the terrain can be saved from the OSD even if 'Save World' has not been checked in the custom inspector.


    Terrain is saved and loaded using the BinaryFormatter and all block data is saved in a single file. World files are differentiated by name so no two worlds can share the same name in a single directory.

    Optimized
    One of the most important factors when it comes to creating any kind of voxel/block engine is optimizing. When you have world sizes in the millions of blocks, with tens of thousands to even hundreds of thousands of blocks dynamically loaded into memory we understand that it is crucial to only store the absolute minimal amount of information required for each block. Not only that but as the player moves around in the world thousands of blocks are constantly being loaded and unloaded from the scene. Combine that with a complex fluid simulation and dynamic lighting and optimization becomes just that much more important.

    That is why Terrain Engine 2D is optimized to maximize performance. Extensive research and work has been put into making sure the engine can perform as fast as possible while maintaining good readability and also having the best possible features. Collider generation, Lighting, the Fluid System, and Mesh Rendering are just a few of the key features that naturally were computationally slow but have been heavily optimized to remove almost all garbage, and now perform exceptionally well.


    I think we will let our benchmarks speak for themselves:



    Terrain Engine 2D is also optimized to minimize memory usage. Each block alone stores a necessary 4 bytes of information which includes the block type, texture variation, bitmask, and a boolean value to determine if that block should be rendered (necessary when using multi-tile blocks). If using the fluid simulation, each block must store an additional 5 bytes of information required for a smooth running simulation. That includes the amount of fluid the block stores (float) and whether the block is stable. Additionally if using the light system, each block must also store a Color32 value (or an additional 4 bytes). That adds up to a total of only 13 bytes per block when using all the features or only 4 bytes per block if not using the Lighting System or Fluid Simulation.

    Example Projects and Demos
    There are two example projects for you to use with the engine, one included with the engine and another which can be found on the Terrain Engine 2D website. The example included with the engine is an example of top-down style terrain, while the example found on the website (the one shown in the majority of the photos and media) is a side-scroller version. Both example projects contain art that is FREE for you to use in any of your projects both non-commercial and commercially.

    Here is a link to the extra example project: https://activegamedev.com/TerrainEngine2D-Example.html


    Here is a link to the demo to try it out: https://activegamedev.com/TerrainEngine2D-Demo.html

    Full Source Code
    All the source code is included with the asset, even the code for the custom inspector. With the exception of the World Custom Inspector script, all code is well documented with XML and commented to explain all the inner workings of the engine.

    API can be found here: https://activegamedev.com/API/html/annotated.html

    Documentation
    As stated above, the source code contains XML documentation and is fully commented. Extensive documentation on how everything works in the engine is currently under development, but all basic information about setting up and using the engine can be found on the website.

    Documentation: https://activegamedev.com/TerrainEngine2D-Documentation.html

    About
    Hi my name is Matthew Wilson, I'm an Engineering student at the University of Waterloo and the sole developer of this project. Over the last year I have fully committed myself to this project in the hopes of making a full fledged 2D Block Engine for Unity. This is only the first step, I have many more things planned for this project and I still feel like there is a long way to go to making this project something truly special and not just what some might refer to as a 'Terraria clone generator'.
    Roadmap
    • Infinite Terrain: The engine is being completely revamped in order to have infinite terrain. All block data is now stored on a per chunk basis and chunks are stored in a dictionary. This allows for infinite procedural generated terrain and infinitely large world sizes.
    • Multi-Colored fluid: The fluid system is being upgraded to allow for multiple different colored fluids, different fluid types, fluid viscosity and the possibility of mixing fluids.
    • Advanced Lighting System: A whole new lighting solution will be coming to Terrain Engine 2D complete with realistic 2d lighting. The new lighting system will contain a number of shaders, post processing scripts, and light sources including; sunlight blocks, flood lights, and raycast lights.
    • Chunk File Saving and Loading: Chunks are now individually saved and loaded using a Binary Reader/Writer. Terrain for large worlds can be pre-generated and loaded dynamically from file.
    • Support for other tilemap styles: Currently there is only support for one special tilemap style, but support will soon be added for multiple other styles as well.
    • Advanced Camera Controller: A more advanced camera controller is in the works allowing for more options and control.
    • Optimizations: There are always more optimizations to be made, and now with the new infinite system many more possibilities have been uncovered!
    TRY THE DEMO - HERE
    I recommend you use Chrome to play the demo. In Firefox there is bug when holding shift and right clicking.


    Support
    Problems - Questions - Bugs - Feature Requests - Other
    If you have any issues feel free to comment below or contact me at:
    contact@activegamedev.com

     
    Last edited: Jun 1, 2018
    AthrunVLokiz, chelnok and JAMiller like this.
  2. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
  3. Endi24

    Endi24

    Joined:
    May 6, 2015
    Posts:
    40
    Nice asset m8! Hope I win too!
     
  4. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    15
    Hi Matthew...looks like a very handy asset indeed!

    I have a question about the level of support you have for top down 2d games. I see you make specific mention about things like water fluids, etc but is there anything you specifically implemented for a side scroller that is not usable for a topdown game? By the look of things I do not see anything obvious, but I thought I should just check with you.
     
  5. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    Currently all features are available for both a top-down and side-scroller type game. Frankly the only difference between the two is how you setup your Terrain Data script for generating the world. The fluid has to have an option since it uses a different algorithm depending on the type of game to account for the direction of gravity. All other features like the block lighting remain the same. I haven't and do not plan on releasing features that will only benefit one implementation and not the other.

    Also I want to mention that the majority of the images being side-scroller has nothing to do with the amount of support the engine has for top-down 2d.
     
  6. Cywizz

    Cywizz

    Joined:
    Oct 5, 2017
    Posts:
    15
    Great, thanks for the quick response and clarity...
     
  7. xu-tom

    xu-tom

    Joined:
    Dec 20, 2015
    Posts:
    2
    Hi Matthew:
    this plugin support mobile platforms?
     
  8. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    I haven't done much testing on mobile, but the major features should work!
     
  9. martin_ls

    martin_ls

    Joined:
    Jul 19, 2017
    Posts:
    2
    Fairly new to unity, so bare with me.

    I cannot get my sprite show in front of the tilemap. I want to use sprite animation for my character.
     
  10. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    What is the material/shader you are using for your sprite? The tiles are rendered in order depending on their Z position. You need to set the Z Position of the GameObject with the Sprite Renderer component so that it is in front of the tiles.

    For further help please join the discord: https://discord.gg/PBphAvq
     
  11. martin_ls

    martin_ls

    Joined:
    Jul 19, 2017
    Posts:
    2
    Thank you for the reply. Further questions on Discord (on the support section).
     
  12. krkim_unity

    krkim_unity

    Joined:
    Mar 30, 2018
    Posts:
    1
    Unity 2D Lighting Technique - When is the update involving the Flood fill algorithm for generating mesh vertices?
    Your assets are very good and I'm looking forward to the next update.
    Can you tell us when the update will be
    I will wait for an answer.
    Have a nice day!!!
     
    dioteos likes this.
  13. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    94
    Does it use tilemaps?
     
  14. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    The update will be released by the new year!
     
  15. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
  16. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    94
    You should use Unity tilemaps. They are faster than any custom system.
     
  17. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    Please explain why you think that is.
     
  18. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    94
    I did some testing. Did you?
     
  19. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    Well I'm not sure what kind of testing you did, but this engine is highly optimized for performance and minimizing memory usage. Just look at these benchmarks, I don't believe it is fair to say Unity's tilemap system is faster than any custom implementation. Faster is a very broad term, specifically what is faster about Unity's tilemap system?

    Skip to 5:34
     
  20. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    94
    Are you saying your system is faster than tilemaps and there is no need to test it?
     
  21. mattwilson180

    mattwilson180

    Joined:
    Mar 31, 2018
    Posts:
    10
    I am saying it is potentially faster than Unity's built in Tilemap System, but I can not test this until you explain what exactly you mean by 'faster'. Do you mean faster setup, faster procedural generation, better in game performance, faster dynamic tile editing, faster chunk loading? ...
     
  22. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    94
    Anything you write with scripts will be slower than source code.
     
    Last edited: Dec 5, 2018