array of boxes

ok so here is my problem, i want to get from point A to point B. but the way i want to do it is with boxes. so say i have a 20x20 plane that is made up of boxes and the array goes from left to right and then down so box 1 would be 1x1 and to the right of that would be 1x2 and below 1x1 would be 2x1.

so say i start at 10x1 and want to get to 10x20(10x20 being point B) i want my algorithm to be smart and know what the boxes next to it are saying. so if we started at point A then our box would first look to the right of it(10x2) and if that spot was deemed walkable then it would then point the character that was on top of it to the box to its right. but if the box to the right(10x2) was not open then it would look down below it to 11x1 and see if that was open and then point that way. and it would go around in a circle till it found away that worked.

i am like brand new to unity coding, but have experience in c++ so i do know how to code, that being said unity is very unique and doesnt quite make sense completely yet. i have started some tutorials and am starting to get the hang of it, but i still dont have a clue how to make an array of boxes like i said. i would appreciate any help at all! but please teach it to me in a way you would teach like a 10 or 14 year old ha ha

PS sorry for it being so long i didnt know how to explain it other than the amount i toke

You could make a two-dimensional array, the scripting reference and this forum has much to say about how to do that.

Why would it be a waste of ram? I may be misunderstanding what you are trying to do, but it seems you’d just be putting additional checks in your A* alg where it checks for availability. Each character could have it’s own A* (maybe that’s where the ram waste is?) but they could share a common 2d array and other structures, if that’s a big concern. If it’s really just 20x20 that’s not too bad. If it were very big, I’d worry more.

Sounds like what you want is Dijkstra’s algorithm:

  • only needs to be recalculated if obstacles are added that change the path
  • all travellers use the one data set
  • very little memory required
  • very fast to calculate

A* is just a variant that is faster for a single traveller and handles multiple destinations. It’s hardly any different though, so I suspect any concern you have is about some particular implementation of the algorithm.