Godot Version
4.5.1 .net
Question
Hello! I’m using godot’s navigation system and I’m struggling with having toggleable sections of the navmap activate when certain events happen. For example, I want the navigation agent to be able to cross a doorway when the door is open.
I tried doing what was reccomended here : How to handle doors (ie, turn parts of the nav mesh off and on)?
but it creates a really weird snapping effect where my agent will only cross over to the doorway region in a really bizarre way where he snaps into the region.
heres my setup in the screenshot bellow and essentially all I would want would be to make the doorway navmap usable by the agent when the door is open.
The doorway region is in navigation layers 1 and 2
The room 1 navigation region is in layer 1
I had tried having a room 1 and then a room 2 but it would work even less and the agent would be stuck in the doorway.
Is there a better cleaner way to do this and one which would be more scalable with game where id have multiple doors. I also considered having the door not be considered by the navmap at all and make it so the fact that the door is physically there be enough to deter the ai.
heres the core of the code. This is called once in the door’s ready function to update it with the door’s initial state ( open or closed) and every time the player interacts with the door.
private void UpdateNavigationFilter()
{
var agents = GetTree().GetNodesInGroup(AI_AGENT_GROUP);
foreach (var agentNode in agents)
{
NavigationAgent3D navAgent = agentNode.FindChild("NavigationAgent3D", true, false) as NavigationAgent3D;
if (navAgent == null)
{
continue;
}
uint currentLayers = navAgent.NavigationLayers;
if (is_open)
{
navAgent.NavigationLayers = currentLayers | DOOR_NAVIGATION_LAYER;
}
else
{
navAgent.NavigationLayers = currentLayers & ~DOOR_NAVIGATION_LAYER;
}
}
}
