Griding Up An Environment: Bones of a Strategy Game by Diogo Vieira Avila


Upon deciding that the game we were going to make was a turn based strategy, the immediate challenge was clear. How do we make a grid? Its simple conceptually, but there are multiple ways to go about it. In our case, we are making a custom AI, so the NavMesh will not be used, with this constraint, the amount of though required on the creation of the feature, since if poorly implemented the game does not happen for the user, and can potentially make level design tasks a living nightmare for the designers.

The first step to solve this problem is creating an architectural vision, essentially how do I want the combat ecosystem to be created. I decided on a single entry-point and origin point format, the entry point the player controller and the origin point being the grid. As an origin point, and the basis of the system, the Grid Spawner (GS), first step in the grid creation, had to be both independent, so it can be placed on any scene for any context, and also highly customizable. To meet these requirements, I made it so the GS has no dependencies, and creates the grid based on a combination of values from three variables: amount of horizontal squares, vertical squares, and square width. 

Here there was a major annoyance, Unreal Engine doesn't deal with 2D arrays. I could do the workaround of creating an array with a custom struct with another array, but decided it would be more fun to figure out how to the grid in 1D format, which came down to creating the mathematical formula to check top edges vs bottom edges of the grid (This approach makes some things harder. Do not recommend, if you are developing a more complex system). 

With the first step out of the way the next part was to satisfy the two requirements for our project:
- Have node functionality, so that the AI can interact with the grid
- Accommodate objects at different heights, and make them all part of the grid

To solve this, I made so the Grid Spawner must be placed in an elevated position on the map, it creates a virtual grid above the map, checking if the desired row and column size fits the map, and adjusting to it in case it doesn't, than proceeding to overlay the map creating Grid Square actors, these square actors have a custom node component with accessible location, and weight. The overlay is done via line trace that way giving me control over where I spawn the grid, after the spawning, The Grid Point actors calculate their neighboring nodes, taking height in consideration (also customizable), effectively solidifying the grid.

Thanks for following me on this journey, it was a blast to create this system, especially not having too much experience on it. It only makes me more excited for the challenges to come!

Thank you and see you next time!

Diogo

Get Project Banner

Leave a comment

Log in with itch.io to leave a comment.