+1 vote

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.

asked Jul 17 in Engine by DamonR (106 points)

1 Answer

0 votes
Best answer
_astar.set_point_disabled(_tileIndex(pp), true)
...
_astar.set_point_disabled(_tileIndex(pp), false)
answered Jul 17 by rakkarage (1,296 points)
selected Jul 20 by DamonR

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 pointtodisable = astar.getclosestpoint(spatialVector3())
astar.setpointdisabled(pointtodisable, 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.

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)

https://gotm.io/henry-software/pixelleveltest
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)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.