Coordinate system settingWhen implementing the movement of the map in games, it has recently become fashionable to use
for a space point of a regular hexagon (hex). It really solves a large number of issues. For example, does not require moving through the corners of a polygon. Six directions for movement is quite sufficient to convey the realism of movement.

Fig.1. Coordinate system
Note that for fixing points on the map, using the Cartesian coordinate system that is so familiar to us becomes unprofitable, since the position of each individual cell becomes difficult to identify without using fractional values in the coordinates, which makes the calculations heavier. Equally non-trivial will be the calculations of the distances between the cells, the calculation of the action of the obstacles during the shot and with it. Thus, the first thing you need to do is choose a convenient coordinate system. The fact that moving to a neighboring cell would correspond to a shift by a single value along one axis of the coordinate grid would significantly simplify the calculations.

Fig.2. Sectors formed by coordinate axes
A close look at the options for the vector directions of the axes is most convenient for me to see the one where the angle between the directions of the axes corresponds to 120 °. 3 coordinate axes correspond to 6 directions of motion.
Such a system is redundant as long as every point in space.
can be described in an infinite number of ways, each of which becomes a trajectory of movement from the origin to a point, but the shortest path is described in a single way by a projection onto the nearest coordinate axes. In fact, we get 6 sectors representing 3 pairs, in each of which the description of points located in them is carried out through 2 coordinate axes adjacent to it as shown in Fig.2.

Fig.3. Coordinates of points
In this view, the coordinates of the points will be fixed as shown in Fig.3.
Convert coordinate to normal viewNormal, we will call such a record coordinates, when it describes the shortest path to it from the origin, which corresponds to the projections on nearby coordinate axes.
To determine that the coordinate is in normal form, we can distinguish several properties inherent in it:
- One of the 3 coordinates must be equal to 0, since the coordinate is recorded in a normal form through a projection onto 2 axes.
The other two coordinates must be in accordance: one> = 0, and the other <= 0 - since half of two axes are adjacent to each of the sectors, one of which is always positive and the other is negative.
These properties are necessary and sufficient to verify that the coordinate is recorded in the normal form.

Fig.4. Single shift in 3 coordinates
Before solving the problem of normalizing the coordinates, we turn our attention to the following property of this coordinate system: a unit shift along all 3 coordinates leads us to the same point (Fig. 4). Based on this, we get pre-education:
(x, y, z) = (x + c, y + c, z + c), where c is a constant
Now, to obtain a normal form of recording, the point coordinate is required only to find 2 axes, an expression through which will give the minimum distance from the origin of coordinates and reduce it to the required form using the formula proposed above. We need to get
(c1, c2, c3), where c2 = 0 and c1 <= c2 <= c3,
which means that before the transformation we had
c2 = c and c1 + c <= c2 + c <= c3 + c,
then in a non-normalized record, it is required to find a coordinate such that its value is located between the values of 2 others and subtract this value from all coordinates of a point.
Calculate the distance between points on the plane
The coordinates of the points are set as the shortest path from the origin to the point, which means that the distance from the origin to the point is equal to
R0 = | x | + | y | + | z |
The difference of the vectors of points gives the coordinate, which in the normal form corresponds to the distance between them.
R = | x1-x2 | + | y1-y2 | + | z1-z2 |
Finding obstacles between points
Now that we have discussed general issues, you can try to solve a puzzle that often arises in computer games with a card.
A shot made at a distance implies the possibility of hitting an obstacle that may be encountered on the way.

Fig.5. Shooting obstacles
This sets us the task of finding an obstacle that a shell can hit. The task has in general 2 approaches to the solution:
- Finding points in space where an obstacle can be located that can interfere with the movement of the projectile and check them;
Go through all the obstacles in the location and check that they are not located in the line of fire.
When considering this task, I tend to the first solution, since the very first obstacle encountered in the course of the projectile, past which the projectile could not fly, completes the solution of the problem, unlike the other approach.
Thus, we don’t always need to go through all the points and all the obstacles if we start the path from the attacker.
There is another argument for this approach. To check the effectiveness of the shelter (obstacle) is often required to know the distance to the shooter or the victim.
In the first case, it is known to us at any time and does not require calculations, and in the second, for each object satisfying the conditions of the obstacle, we need to calculate its distance from the shooter and the victim.
In Fig.5. the point A is indicated by the shooter, and B is the victim. The dots may be obscured in gray.
The shift in the cells during the passage along the “cell” straight line, which is the movement of the projectile, will occur in proportion to the shift along the coordinate axes. The third coordinate for solving this problem will not be used, because the vector of the shot will be in normal form. Since the shot starts from the middle of the cell and ends in the middle of the cell, the result will require rounding.
y = y (AB) / x (AB) * x
Results
In this review, I was able to consider only some particular points encountered in games with a map, which was done in order to demonstrate a convenient coordinate grid.
Note again that the choice of such a coordinate system reduces most of the calculations to arithmetic. All coordinates are integers, give a convenient opportunity to describe the routes of movement of the character and clearly indicate the direction of movement.
The cost of such a system can be considered as its redundancy, which is compensated for by a simple rationing system.