#AStarGrid2D Out of Bounds issue

1 messages · Page 1 of 1 (latest)

bitter cape
#

I'm running some tests with my new AstarGrid2D I made but I haven't gotten past the first test since it thinks 43,46 is out of bounds, which it can't be because the size is 162x80 so like- idk how that point is out of bounds. I'm genuinely stumped. I can't find anything in the docs or in tutorials about this.

I found the cut off points where it starts thinking it's out of bounds which is 117 and up for x and 35 and up for y. I tried posting in beginner initially but it seemed like more of a complicated issue with not an easy fix so I moved it here. I apologize if it ends up being something dumb I've just been stuck on this for weeks now.

stoic radish
#

It's adding to e and i. The for _ in _: means it'll do that part automatically

bitter cape
#

Oh right I already fixed that lol forgot to put updated screenshots srry
It still has things out of bounds even without that

stoic radish
#

From that error message, I guess the region starts at -45,-45 (based on that wall?)

(43,48)-(0,2)+(-45,-45) = (-2,1)

which is probably out of bounds. See if adding (2,0) to the starting point works.

bitter cape
#

Oh wait- so the AStarGrid2D starts mapping at 0,0 and the tilemap starts at -45,-45

stoic radish
#

I'm not sure, that's my take from the error gdthinking

bitter cape
#

Hmm.. is there a way to change how th TileMapLayer maps each cell so I don't have to use offsets?

stoic radish
#

It comes from walls.get_used_rect() so that needs to be changed before setting it I think.

bitter cape
#

Oh I thought I'd apply the offset to AStarGrid2D so it matches up with the used rect

stoic radish
#

Gotta clarify:
Is this path finding taking place in world coordinates, or tilemap coordinates?

bitter cape
#

The coordinates relative to the AstarGrid2D

#

Since that has all the solid points stored on it and everything

stoic radish
#

Like, at tilemap coordinates (2,1) might be world coordinates (32,16)

bitter cape
#

Oh

#

Tilemap coordinates

stoic radish
#

Okay. Let's make sure it knows that.
Delete the line with set_cell_size because that's saying each cell is 16 units (which makes sense for world coordinates but not tiles)

var grid := AStarGrid2D.new()
grid.region = Rect2i(Vector2i.ZERO, walls.get_used_rect().size)
grid.update()
#

And the region can start at zero if your tilemap starts at 0.

bitter cape
#

Huh

#

That actually fixed it