# Calculating grid based maximum movement with obstacles.

i want to make an xcom like game and right now i’m stuck at field that shows how far character can move, i have an idea how to make a field but i have no clue how to make this field consider obstacles, because if i make a field that do not consider obstacles than it will show up at the other side of the wall, but it’s not my main problem, i’m at a loss with more complex obstacles that still lets you go around them but not too far

The general solution to this will be to implement a pathfinding system such as AStar.

There are plenty of Youtube and other tutorials for setting that up.

What you would do for the specific effect you want above is to iterate all squares within a reasonable distance from the player (or even iterate every single square on the board), and then query the AStar to find how far that path is length-wise.

Then you can decide if that path is less than or equal to the maximum distance the player can use, and if so, add that square to a list of available destinations right now.

Once you have done that for all squares, you now know which squares to display as walkable in your UI, and accept valid input only for those squares.