Okay so I got the AI working thanks to the kind people in my other post, however I have a new issue now. What my AI is currently doing, is moving next to the closest opposing unit. What I want to do is make it move so that that the AI unit is attacking from it's furthest attack range distance, as this makes more sense. Obviously if the AI unit's attack range is only 1, then it can keep moving up to the target, however I don't know how to do it if the range is greater than that. The unit's can not move diagonally. Here's a diagram I made (with made up symbols): The red square is the AI unit. The blue square is it's target that it wants to attack. The pink cross is the location I want to know how to find. The dotted line is just an example path of how to get there. The green squares are the locations that are within range at the point I want to find. How do I find the ideal location (pink cross's location) so that the AI unit is moving to it's maximum range that it can attack from? Also, the AI unit could be anywhere on the grid, not just the location in the diagram. Not sure on how to approach this.