Hex Grids love Vectrosity
Good news at last, I just finished the finding functions for vertices, both in grid space and in world space. Here is a screenshot where the yellow gizmo indicates the vertex closest to the grey sphere.
Good news at last, I just finished the finding functions for vertices, both in grid space and in world space. Here is a screenshot where the yellow gizmo indicates the vertex closest to the grey sphere.
The other day I had the following problem: I had a list of Transfoms and I wanted to remove the entries that met a certain condition. This is what I had written:
Surprise update! Version 1.1.9 just got approved and it contains quite a few changes:
The align feature has been giving me quite some headache lately. For small objects it’s easy, just fit them inside the nearest hex. It gets more interesting once your object spans over more than one hex. Here is a screenshot from the game “Age of Wonders” for PC (I upscaled the image manually, AoW has a very low resolution)
Another progress update: WorldToGrid and GridToWorld are now implemented. For those who don’t know, those two functions convert a point’s coordinates from world space to grid space, the coordinate system used to locate points relative to the grid’s properties, and back. For rectangular grids it’s a fairly simple idea, the grid can be represented as a standard Cartesian coordinate system. With hex grids that won’t do it, you simply cannot force a hex grid into a Cartesian coordinate system, you need to find something else. Fortunately there are several topologically identical possibilities with easier, more intuitive coordinate systems. For the first release I have decided to use the herringbone pattern:
The 1.1.10 update brings in a new function, ScaleVector3(Vector scl) : Vector3 which takes in a vector and then scales it so it fits inside the grid. This is similar to AlignVector3, which was introduced in the last update, to allow performing the aligning and scaling without having to provide an actual Transform.
The wait is over, version 1.2.0 is out, bringing you the long promised hex grids. I’ll soon make a video demonstrating the new grid, in the meantime let me explain it in words. My implementation brings you all the features you knew from rectangular grids, except on a hex grid, and both grids inherit from the same base class. This means the API for both is the same and you can write one script for both grids with little to no need to make special adjustments for different grid classes. Currently there is only one coordinate system and hex grids have “only” as much functionality as rectangular grids. I wish to improve upon this in the future.
Just a quick update, version 1.2.0 has been submitted. This is your last chance to buy the package for 15, once it has been approved the price will be raised to 20.
I made a short video giving you an overview of hex grids, so you can see them right in action. I’ll make a video on how to extend Grid Framework with your own methods yourself next,
Let’s say you just bought Grid Framework, wrote some game logic and now you want to reuse it. Wouldn’t it be great if it was a class method in Grid Framework so you could simply call it with one line of code? Even better, what if you could have one method that has the same syntax for both rectangular and hexagonal grids but different implementation based on the type of grid, so you would have to write just one script for any type of grid? Luckily this is no problem in Unity thanks to extension methods and if you have the code, then wrapping it up into an extension method can de done in a few minutes. Take a look at my latest video tutorial: