# Walk to nearest attackable range node

My game has 3D environment which is partitioned in 2d cells(nodes). I have implemented A* for path finding.

Now I am just breaking my head to how to implement the algorithm to move the hero to the nearest attackable range node/point when the enemy is out of attack able range.

Which means, it should satisfy two conditions

1. Target whithin attackable range
2. No obstacles in between the target and attacker

See below picture (pardon for my bad drawings)

• Brown boxes are obstacles
• Attacker/hero is in the cell highlighted with Turquoise color dot, the circle is the radius/size of the model.
• Target is the red dotted color cell, surrounded with red color circle to indicate the size of the model
• Green circle is the radius where hero has to move to some where inside that location to attack (its the radius of hero's attack range)
• Blue dots are the A* path to reach from hero position to target position

When the player issues attack command, hero should move to the nearest attack able node and start attacking.

Finally I thought of below algorithm

2. Get nodes fall within the radius (from step 1) from targets position
3. Find path from attacker to target using A*
4. Keep walking in the path (from step 3)
5. check if current node is in the scanned nodes (from step 1)
6. If true,
7. Check that no obstacle are in between
8. If true, attack, if false keep walking (repeat step 4)

If we put together the algorithm and the figure1

The A* gets the path of 9 node to reach the target After moving 5 steps, it enters the attackable range, since there is obstacle between the target, it take two more steps where it finds no obstacles and stats attacking.

I am not sure if this is the optimized method to achieve this but I am not getting alternative solution.

Very particular to the steps 2-5 which looks little weird and process intensive to me.

I am using actionscript 3 and Flare3D (Stage3D API)

-