# finding/calculating allowable moves on a grid

Hello everyone! Thanks for taking the time out to read my question. I am looking for opinions and advice on the best way to calculate what tiles an object is allowed to move to. To best describe what I am looking to do, and what i have done, ill throw some illustration below.

A = allowed
X = not allowed
O = object

XXAXX
XAAAX
AAOAA
XAAAX
XXAXX

I am currently using Raycast.Overlap Sphere to cast a sphere with a length equal to how many movement points the character has but am not able to get the desired result. The result I am getting is below

XAAAX
AAAAA
AAAAA
AAAAA
XAAAX

it is picking up the diagonals which i dont want.

Basically what i am looking to do is calculate tiles the player is allowed to move to and the player is NOT allowed to move diagonally. Is there a better way the raycast sphere, or just raycasting in general, to calculate this? Thanks for all advice!

It would be much simpler to use an array. As a basic example, say you use a 2D int array to represent the tiles, and the character is at [5, 5], and you want to see if he can move one space to the right. So you’d check [6, 5] in the array. Likewise you’d check [4, 5] to see if he could move one space to the left.