Godot Version
4.3
Question
i’ve been trying to optimize the 3D navigation as much as i could for a large world + lots of navagents (i think i’ll be fine with a cap of 200 agents at maximum).
at this point i have a global navigation node which sends target_location to a queue of navagents sequentially every 0.1 seconds, this time could change however depending on the amount of agents in the scene, i’d wish to make it distance-dependant as well so the further the player is from the agent, the less target_position updates it requires, however that feature kind of conflicts with the queue method, where i assign target_positions one by one, because if one agent is far away everyone else will have to wait for his very time consuming (due to him being far away, as i mentioned) target_position update. I’d like some ideas on how to get the best of both worlds here if possible
on top of queueing the agents, i’ve tried grouping them when they’re close enough and ungrouping some when they leave the proximity of the “leading” agent. when a group is created, i assign the first agent to join the group as a “leader”, anyone joining past this time is a “follower”. “followers” follow the “leader” as the names suggest, and they inherit the “leader” 's current_navigation_path, instead of computing a path themselves. although it looked promising at first i didn’t like the idea of them sticking together into groups, i thought that visibly they would still look spread apart while moving in one general direction but that wasnt the case.
the only thing right now that is really eating perfomance is when an agent tries to find a path when there are none that are reachable, to my assumption due to it trying out every single combination of paths, right now i’m throttling the target_position update when at least one of the agents target_position is considered unreachable, and only trying it out every like half a second as opposed to 0.1 seconds until it becomes reachable again by one of the agents and as a result, resuming back to 0.1s update timer. this made almost no difference and i could still see the lag spike caused by the agent trying to find a path to an unreachable area.
besides this, i’ve also split my world geometry into “chunks”, and used a navigationregion3d for each of the chunks as opposed to just one large navigation region, i expected this to do some magic behind the scenes but i dont think it did much since the lag spike issue ive talked about persists with it
and if that wasn’t enough, if an enemy has the player in direct sight (not obstructed by any static bodies), then it will throw away all its navigation related stuff and just move towards the player direction
is there anything else i’ve missed out on that couldve been a major perfomance optimization? i’m ready to manually make a navigation mesh for the world geometry if that improves it substantially from what i have got already. thanks in advance, here are some screenshots to get the rough idea of the node hierarchy:
if !enemy.agent.is_target_reachable(): isReachable = false continueNext() continue
< didnt fit in screenshot
tl;dr: any 3d navigation perfomance optimizations that arent grouping agents, turning off navigation when in direct sight with the player, queuing agents, splitting the world into multiple navigationregions3d (unless i’ve missed something valuable here but it didn’t improve anything afaik) and most importantly fixing lag spikes when agent cant reach player’s position