Preface
On this page I'll explain how the following Systems work:
-
Hex connection
The system I made that assigns a tiles neighbours using ray casts in the Start function.
-
Astar system
The System I made using the A* Algorithm which determines the hexes a unit can move towards and
what the cheapest cost is to move there. This uses the ProcesAStarPathfinding function and the
AStarStep function.
-
Movement
This system checks if a tile can be accessed by a unit and if so, goes through the needed steps
to move a unit there. This uses the ProcesUnit function.
Hex connection
- Hand made,
hex based map Each hex holds a reference to its neighbour
Summary:
I wanted a
simple and quick solution to the "map"so I could implement A* movement on. I decided on a
hand made Hex based map where each hex holds a reference to its neighbours.This was done using a ray cast from each side, shot at the initialization of the game.
Hexes initializing
Astar system
First time working with pathfindingA* pathfindingCheck neighbouring tiles for movement costCheck if the cost is below or at the current movement pointsRepeat
Summary:
When selecting a unit, A* is used to decide which tiles are reachable. It decides this by
checking all the neighbouring tiles and that tiles neighbours for its movement cost.If the
cost is less or equal to the units remaining movement pointsthe tile will become grey. It will
continue till it fails one of these checks.Some tiles are checked more than once, in which case
the actual cost to move there and the path the unit takes is the cheapest option.
the tiles it can move to become grey
Movement
With a unit selected, pressing right mouse on a tile checks:Isthe tilepassable?Isthe tilereachable?(A* checks decided this)If both steps pass:Deduct movement costsfrom unitAdd the unit to the tileMove the unit visuallyUnselect unit and reset tiles
Summary:
While having a unit selectedit can move to any highlighted tile.
Pressing right mouse buttonstarts this process.
If the tile pressed on is either not in the A* calculated range or on an inpassible tile the move will fail.
If the tile is within range the movement cost will be reducted,
the unit will both visualy and in the data move to the new tile,and the
tile costs and visuals will be reset.
The unit moves to a reachable tile