+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.


in Engine by (114 points)

1 Answer

0 votes
Best answer
_astar.set_point_disabled(_tileIndex(pp), true)
_astar.set_point_disabled(_tileIndex(pp), false)
by (1,863 points)
selected by

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.



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)

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.