![]() Give it a slight vertical offset so its contents will appear on top. Set its pivot to zero and its position too. Set the Render Mode to World Space and rotate by 90 degrees around the X axis so the canvas overlays our grid. You can also delete the event system object that was automatically added to the scene, as we don't need it yet. As this is a purely informative canvas, remove its raycaster component. Showing CoordinatesĪdd a canvas to the scene via GameObject / UI / Canvas and make it a child of our grid object. It would be convenient if we could see all cell coordinates at once. But which cell is where? Of course that is easy for us to check, but it will get trickier with hexagons. This gives us a nice grid of seamless square cells. using UnityEngine public static class HexMetrics Square grid of planes. Let's put these metrics in a static class for easy access. The inner radius is equal to `sqrt(3)/2` times the outer radius, so `5 sqrt(3)` in our case. This metric is important, because the distance to the center of each neighbor is equal to twice this value. There is also an inner radius, which is the distance from the center to each of the edges. This defines the outer radius of our hexagon cell. Because a hexagon consists of a circle of six equilateral triangles, the distance from the center to any corner is also 10. ![]() Of course a hexagon grid is less straightforward to construct than a square grid, but we can deal with that.īefore we get started, we have to settle on a size for our hexagons. So there is only one kind of neighbor, which simplifies a lot of things. All of these neighbors are edge neighbors. A hexagon and its neighbors.Ĭompared to a square, a hexagon has only six neighbors instead of eight. One approach is to not use a square grid at all, but to use hexagons instead. If you use discrete movement, how do you treat diagonal movement? Do you allow it at all? How can you create a more organic look? Different games use different approaches, with different advantages and disadvantages. The differences between the two kinds of neighbor lead to complications. But for diagonal neighbors the answer is √2. What is the distance between the centers of adjacent square cells in the grid? If the edge length is 1, then the answer is 1 for the horizontal and vertical neighbors. The other four can be reached by crossing a corner of the square. They are the horizontal and vertical neighbors. Four can be reached by crossing an edge of the square. Take a look at a single square in the grid. Squares are indeed simple to draw and position, but they have a downside. Why use hexagons? If you need a grid, it makes sense to just use squares. There is now also the Hex Map project, which modernizes Hex Map and uses URP. The final part is made with Unity 2017.3.0p3. The entire series progresses through multiple versions of Unity. This tutorial assumes you have completed the Mesh Basics series, which starts with Procedural Grid. We will start with the basics, incrementally adding features until we end up with a complex hex-based terrain. Many games use hex grids, especially strategy games, including Age of Wonders 3, Civilization 5, and Endless Legend. This tutorial is the first part of a series about hexagon maps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |