Implementing Lockable Doors in Navigation2D

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

Hi All,

I have a working solution to this issue, but I am mostly concerned about the scalability of my solution. I am using a Navigation2D object for pathfinding in my game, and one of the obstacles my NPCs might have to navigate around are doors that are locked or unlocked. The NPCs are easily capable of navigating unlocked doors, but I had some trouble getting them to recognize locked doors. My solution was to break up my navigation polygons into one for each individual room, and then give each lockable door its own navigation polygon. Then, I add the navigation polygon as a child of the Navigation2D if the door is unlocked and I remove the navigation polygon as a child of the Navigation 2D if the door is locked. Is this a viable solution if I anticipate having a maximum of maybe 30ish rooms in a level? If not, is there a better way to implement doors inside of a Navigation2D?

For what it’s worth I came to the same solution as you. However rather than adding and removing the doors’ navigation polygon from the tree, I just enable and disable it using the ‘enabled’ property. This works fine in my situation. If you/anyone has a better solution I’d also like to hear it :slight_smile:
[Godot v3.5.1]

[Steve] | 2022-12-03 15:15