How to disable astar points within an area.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DamonR

I have followed miziziziz’s YouTube video ( https://m.youtube.com/watch?v=A1xjUuRZmWQ ) and setup an astar grid map for an rts demo. But I have been unable to work out how to disable astar points within an area for when placing buildings. I have searched online, and have even looked at dynamic obstacle avoidance, but nothing I could find explains how to disable and re-enable astar points.

Any help is appreciated.

Thank you for your time.

D.

:bust_in_silhouette: Reply From: rakkarage
_astar.set_point_disabled(_tileIndex(pp), true)
...
_astar.set_point_disabled(_tileIndex(pp), false)

Hi, thanks for answering. I have managed to get the code to work using some spatial nodes placed roughly where the grid points will be, and using something like;
var point_to_disable = astar.get_closest_point(spatialVector3())
astar.set_point_disabled(point_to_disable, true)

After much trying, I still wasn’t able to get the grimap cell reference. Perhaps I have missed something, I haven’t worked much with gridmaps yet. How would you go about getting the gridmap index? I looked at how Miziziziz does it in his code, but am still at something of a loss.

As your answer helped me figure out how to disable them using spatials, I will mark it as answered.

Thanks.

D.

DamonR | 2020-07-20 17:15

enter image description here

this is the best way i think because you can convert between position and index with a function

static func index(x: int, y: int, width: int) -> int:
	return int(y * width + x)

static func position(index: int, width: int) -> Vector2:
	var y := int(index / float(width))
	var x := int(index - width * y)
	return Vector2(x, y)

rakkarage | 2020-07-20 19:43

gotm.io | gotm.io
and here is a working example where i disable a point when i close the door and it affects astar pathfinding (can only toggle door when standing beside it and click on it)

rakkarage | 2020-07-20 19:48