Challenge: Moving to target units

When you have a selected unit and move the cursor over a target unit, nothing happens. The target is invalid in the project’s current state.

In those cases, offer the player to move to a cell in front of the target closest to the moving unit, as shown in the picture below.

Here’s a breakdown of how the feature should work.

Steps:

  1. Select a unit.
  2. Move the cursor over a target unit. A path should draw to a cell in front of the target unit.
  3. Press enter. The selected unit should move along the path.

The code should also take into account if another unit occupies the cells surrounding a target unit, as illustrated below.

Hints: