Hi, I’ve been making trying to make a 2D game with a side-view camera and I’ve been implementing slightly more by-hand pathfinding for it using Astar2D class instead of navigation regions. Generally it’s been working pretty well, but I don’t know how I can expand it further - I would like to have ‘locked doors’ that navigation actor can only pathfind through if it has an appropriate key in it’s inventory. I don’t want to like affect weights of the points directly because I want different navigation actors to have access to some paths and others not.
I dont have much experience with pathfinding, especially in godot but i think you could treat the doors as obstacles unless they have the key then you can remap the navigation? Like each time you get a key, remap the navigation with the relative “Obstacle” removed.
From what I understood when reading about NavigationObstacles, they are used for baking nav meshes and for avoidance calculations used by NavigationAgent nodes. In my cases I wanted like side-view 2D game, so I wanted my agents to respect gravity and only climb levels on ramps so instead of using Godot’s all of built-in nodes meant for navigation I used just Astar2D class to basically ‘draw the graph’ myself. Here is how it looks right now:
So I dont think I can even use godot’s other built in nodes for this
You can use the set_point_disabled method of your AStar2D instance to temporarily disable a point.
This means: Place a point at your door. When you do a path search for a character, check if this character has the keys necessary to traverse the door. If yes, then enable the point of your door - if not, disable it.
For convenience, you probably want a class either wrapping or extending AStar2D to have a clean interface.
I actually like that solution to this problem. One follow up question I’d have - How can I extend Astar2D class and have that extension visible globally. If I give class_name to node based classes, they can are visible globally and can be instanciated but Astar2D doesn’t inherit from Node so it will only be in-scope to use in the script that defines it right?
Ideally for reusability I’d rather define that extended class in a seperate file and then just have something like:
var custom_astar = CustomAstar2D.new()
in a script that wants to use it. Is that possible or do I have to settle for defining it inside a single file?