Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Released] Tile-Based Worlds Framework

Discussion in 'Works In Progress' started by AndyGainey, Dec 2, 2015.

  1. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216


    Tile-Based Worlds is my work-in-progress collection of scripts for creating and using abstract vertex/edge/face data structures as a foundation for tile-based games.

    Update 2016/04/08: It has been accepted onto the Asset Store: Get it here!

    As an offshoot from a planet generation prototype I created last year, these scripts will provide utilities for defining a wide variety of regular and irregular tiled surfaces, and for integrating them with any tile-based game mechanics and user interface elements needed for your game, such as placing units on tiles, efficient mouse picking, and path finding.

    The bulk of the scripts are raw C# classes and structs, meant to provide the data structure backbone for game mechanics, rather than drag-and-drop functionality from within the editor, though the more common functionality will certainly be provided as easily usable components when possible.

    Evolving from a planet generation background, spheres were the first type of surface that I implemented, but other common surfaces are also planned. Flat projections for topologies that optionally wrap around at the edges will definitely be supported also, and will have access to same range of creation and interaction utilities that go well beyond simple square- or hex-based tiling systems.



    These alternate tiling patterns can easily be used to reinvent new variants of existing games, so as this example with Go:



    Currently Implemented:
    • Spherical topologies generated from triangle/square subdivisions of tetrahedrons, cubes, octahedrons, and icosahedrons.
    • Planar topologies supporting both square and hex grids, capable of wrapping around on the horizontal edges, vertical edges, both, or neither.
    • Randomization of tiles to produce an irregular topology. Particularly good when paired with spherical topologies where there would otherwise be predictably placed tiles with a different number of sides than the majority.
    • BSP tree generation for enabling efficient mouse/ray picking.
    • A* path finding, supporting whatever cost calculations and heuristics are applicable to your game.
    • Dynamic mesh generation, with submeshes automatically generated whenever the vertex count goes over 64K.
    • Random adjacent visitation of faces, used in the examples above to generate the colored regions by randomly flood filling the entire surface starting from a fixed number of seed faces.
    • Vertex/Edge/Face attribute calculations (face centroids, face/vertex normals, edge midpoints/lengths, face/vertex areas, et cetera).
    • A clean API for navigating through topologies no matter how complex they are.
    • Convenient UI for generating assets from the editor, with most of the actual generation API accessible during run-time also.
    The following tutorial video walks through some of the core functionality to create a hex-based work with mouse picking and path finding:



    Planned Features:
    • Flexible movement rules, such as distinguishing between 4-direction and 8-direction movement on a square grid, or the more complex movement rules of chess.
    • Mesh generation for region outlines, paths, and any other line-based visualizations associated with a topology.
    • Voronoi-based tile generation.
    • Advanced planet generation demo.
    • Automatic wrap-around world rendering through integration with another upcoming asset for working with wrap-around worlds generally (both tile-based and not).
    Questions for the Community:
    • Is this something you could use?
    • Does it motivate you to want to build a tile-based game using some of the features that go beyond a simple square grid?
    • Does it look like it could make any of your past, current, or future projects easier? Or does it mostly reimplement functionality that you think would be easy enough to implement yourself, with any additional functionality being stuff which you wouldn't care to use?
    • Are there any features which you think would be a natural extension to this tool set which I haven't mentioned?
    • Would you have any preferences for how you would interface with the tool set? Through code or through the editor and component inspectors? If the latter, what type of components would you envision, and what type of flexibility would they expose through the editor?
     
    Last edited: Apr 8, 2016
    Martin_H likes this.
  2. Psygantic

    Psygantic

    Joined:
    Mar 4, 2014
    Posts:
    10
    Do you plan to include your work on realistic biome generation based on plate tectonics, temperature, humidity, etc.?
     
  3. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    For this asset, probably not. My aim is to keep it generic so that it can be widely usable for many different types of games. Future assets that I might work on might very well build on top of this foundation, but those are not a priority at the moment.

    Upon consideration though, as part of an example scene, I might include a quick port of my planet generator which I linked above. The conceptual work is already done, and I need some good sample scenes anyway, so that would be an ideal approach to take. Also, since that prototype is already released under a very liberal license, I wouldn't mind including nearly the same algorithms in a demo of this tool set, so that you could easily build a game on top of it. I'll keep this thread up to date if/when I work on that example scene.
     
  4. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    98
    Hooooo, this is awesome <3

    I've been following your project for a long time now, I was thinking about buying your tool and porting it to Unity (like those guys were trying to : https://github.com/alprkskn/RandomPlanetGenerator).
    But knowing you are on it, I will definitely buy your asset, especially if you port your biome system !
     
    Andros_Spica likes this.
  5. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Nothing new to show yet. The next feature that I started working on ran into some stumbling blocks. I have curved surfaces working as shown above, but I wanted flat surfaces too, even if they wrap around at various edges like so many games do. The problem isn't with the topologies themselves, but with rendering them.

    I was surprised to find that there's no simple out-of-the-box way to do this in Unity, especially if one wants things like shadows and lighting or physics to work seamlessly at the edges. So right now I'm in the process of figuring out a system that will work for flat topologies, and I might have stumbled upon an architecture that will work fairly easily not only for this particular situation, but generically too! Might be valuable even as a standalone asset, but will be included in the topology asset also, since it would be a vital component.

    I'll post more next week. Right now it's time to take a break and get my head in gear for Ludum Dare!
     
  6. ChickenKev

    ChickenKev

    Joined:
    Jan 17, 2016
    Posts:
    2
    • Is this something you could use? Yes
    • Does it motivate you to want to build a tile-based game using some of the features that go beyond a simple square grid? Yes: This is something I've been struggling with over several different implementation attempts
    • Does it look like it could make any of your past, current, or future projects easier? Yes.
    • Or does it mostly reimplement functionality that you think would be easy enough to implement yourself, with any additional functionality being stuff which you wouldn't care to use?

      No:
      It will be interesting to see how it works with existing features I've implemented such as terrain deformation, splatmaps and custom shaders. For me on my current project a planetary grid system has been the hardest part.
    • Are there any features which you think would be a natural extension to this tool set which I haven't mentioned?

      Yes:
      It would also be nice to include some of the climate simulation and be able to export the height map data and (if implemented) moisture and temperature data from the examples here: https://experilous.com/1/blog/post/procedural-planet-generation as a bitmap texture that could be used as a source for splatmaps as mentioned above.

      I'd love to see some of that weather simulation from the blog working over a time system. For example you could have a rate at which heat is added to all tiles (such as from the sun) and then tweak the parameters to control how quickly this spreads and dissipates across tiles on the map. For my project I have a particular need for something like this but it may not be a common feature for all types of gameplay. That said if it was written in a generic way you could have custom properties that spread across the tiles in a similar way and it could be used to create systems like unit moral or other environmental factors beyond just weather. Probably a ton of work :p so you might want to validate this idea.
    • Would you have any preferences for how you would interface with the tool set? Through code or through the editorand component inspectors? If the latter, what type of components would you envision, and what type of flexibility wouldthey expose through the editor?

      Both:
      I'd want to be able to work with the code easily enough to implement custom features such as those described above but I would not want to have to initialize everything with code.
    Hope some of that helps. And thanks for all your work so far.
     
    RDeluxe likes this.
  7. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Thank you ChickenKev for the feedback! And for anyone intrigued by my first post, I'm pleased to finally offer an update on my progress. Sorry I've been quiet for so long. Most of my work was in the form of redesigning the API (repeatedly) and the integration with the Unity editor, trying to make things easier to use. This sort of work doesn't tend to produce outwardly visible results.

    But I've finally found a design that is really feeling natural and effective, and features and polish are starting to happen again!

    First off, a bit about the editor integration. I took some time to better understand the ScriptableObject class, and that allowed for a much better design for generating and storing the data that my plugin produces, and attaching that data to game objects in a convenient fashion. The UI for the generators actually looks very similar to the standard inspector UI for game objects and components:



    When you click the [Generate] button at the top, it will generate and save the assets into a few organized .asset files in the path specified, which ends up looking like the following:



    I'd like to embed them all into a single .asset file, but Unity unfortunately doesn't allow arbitrary nesting, so grouping them as shown is the best compromise that I've found thus far. The top item in each of those lists is the actual generator which keeps track of all the configuration and generated assets. Selecting that will show the full generator UI in the inspector window as seen in the first screenshot.

    You'll notice a lot of references to planar manifolds in the above screenshots. That was one of the areas that surprisingly required some major re-architecting, in particular, wrap-around worlds that were pervasive during the 2D era, but are trickier with modern 3D rendering and physics engines. I've finally found ways of representing the wrap-around information that should be very flexible for world generation, and ways of using that information to make rendering and physics work with little effort.

    Here's a quick video demonstrating a bit how this wrap-around process works. On the left is the Unity editor scene window where you can see what's happening within the engine, while on the right is the view as seen through the in-game camera, showing a seamless transition across the wrapping edges of the world.



    With luck, I'll be able to really pick up the pace with the addition and completion of features. Not to mention all the valuable polish that is inevitably lacking partway through a project's initial development cycle. :)
     
  8. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Got the planar hex grids working, and they support plenty of flexibility, depending on how one wants to arrange them and index into them. Here's a sample:



    The method of indexing them using 2D or 3D coordinates is currently dependent upon the shape of the world, but I'll be adding ways to use specific types of indexing schemes regardless of the overall shape.

    Beyond hex grids, I've been adding a variety of polish. I'm thinking it's about time I start wrapping things up for a private beta test in the next week or two. Still plenty of usability issues and missing features that need to be dealt with, but with an initial pass at documentation, I think it'll be close to ready for trials and feedback.
     
  9. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    The polish is coming along quite well. I've cleaned up a lot of the rough edges and the framework is really becoming quite pleasant to use. I've thus been able to squash a sufficient amount of shame to allow a few colleagues to give it a try and offer feedback as I continue to wrap up remaining critical features necessary for a version 1.0 release. Mid-March is my current aim.

    For visual fun, here's the result of getting my wrap-around framework fully functioning with a perspective camera at any angle:

     
  10. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    Over a month later, I can finally claim to have submitted the framework to Unity for review! Below are some shots from the example scenes I put together.

    This first is just a sample of different planar tiling patterns, pre-generated from within the editor:


    This next is from a spherical path finding demo. The continent and biome generation is unfortunately very simplistic, but does it's job for demoing the basic concepts. A future update is likely to include a more robust planet generator using the tectonics and weather patterns from my 2014 prototype.


    Here is an example of remaking an existing game (Go) using a non-standard tiling pattern:


    I put together a tutorial video, and here's a shot of the end result, with a path finding action in progress:


    If the package passes muster with the Unity reviewers, this should be on the asset store within a couple of weeks. I have a second one coming soon also, which handles wrap-around rendering and other wrap-around world functionality (whether for tile-based worlds or fully continuous worlds, like the old arcade game Asteroids). I had intended to release them simultaneously, since they can be used together very well in particular situations, but the wrap-around worlds asset needs a substantial redesign to make it easier to use. Hopefully that'll get finished and submitted later this month. The Tile-Based Worlds framework can handle the generation and navigation of wrap-around worlds as is, but the rendering of repeating worlds is beyond its scope.
     
  11. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    jason-fisher and RDeluxe like this.
unityunity