#Getting a character's movement range

1 messages · Page 1 of 1 (latest)

stoic oasis
#

I have an AStarGrid2D. How do I get all tiles that are reachable with a movement stat from a given starting position? Tiles can have different weight scales.

sonic void
#

Start by iterating every tile in the map, getting the path there and measuring it, discarding all paths that are too long. If that’s too slow, figure out how to check fewer tiles, like only checking in an area around the character.

whole hare
#

I would probably write a recursive function that takes the current cell index, remaining movement, and results array, then repeatedly calls itself on the neighboring indexes until the remaining movement is exhausted.

The logic would be roughly:

  1. If remaining movement <= 0, return.
  2. If the cell doesn't exist at the index or has a bad weight, return.
  3. Add the index to the results array if it doesn't already exist.
  4. Reduce remaining movement by weight at index.
  5. With the new remaining movement, call the function on each of the neighboring cell indexes.