Home
Project period: 2018, for a short period of time.

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 Gif missing

Astar system
  • First time working with pathfinding
  • A* pathfinding
    1. Check neighbouring tiles for movement cost
    2. Check if the cost is below or at the current movement points
    3. Repeat
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 points the 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.

Selecting a unit makes the tiles it can move to become grey Gif missing

Movement
  • With a unit selected, pressing right mouse on a tile checks:
    1. Is the tile passable?
    2. Is the tile reachable? (A* checks decided this)
  • If both steps pass:
    1. Deduct movement costs from unit
    2. Add the unit to the tile
    3. Move the unit visually
    4. Unselect unit and reset tiles
Summary:
While having a unit selected it can move to any highlighted tile. Pressing right mouse button starts 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 Gif missing

Click Here to go to the Github