Solving lag for hundreds of agents?

I’ve got about one hundred agents charging toward the player, however with that many I’m finding the paths for all of them lag behind so they are constantly moving toward a location several points from the player.

I’m currently using a recast graph with RVO controller / RichAI. RVO controller is set pretty low I think. I’ve got a funnel and advanced smooth modifiers on the agents as well. I’m trying to maximize the number of agents here - what are some other things I can do to get the repath rate to calculate more quickly?

Hi

Take a look at https://arongranberg.com/astar/docs/optimization.php

Here are a few other things you can try:

  • Make sure you have multithreading enabled, you should probably leave it at ‘Automatic High Load’

  • The AdvancedSmoothModifier and FunnelModifier components will not do anything except add some overhead if you are using the RichAI component. RichAI uses its own internal funnel modifier which it executes every frame instead (optimized for that particular use case, so it is pretty fast). So you can remove those two to improve performance a bit.

  • Try to use double buffering on the RVOSimulator if possible, this might introduce too much latency however, it depends on the game.

  • Try to predict the position that the player will have in the future. Something like:

    // Try to predict where the player will be 0.5 seconds into the future
    targetPoint = player.position + player.velocity * 0.5f;

  • Reduce the repath rate dynamically for agents that are far away from the player to avoid them using unnecessarily large amounts of CPU time.

  • Try not to use any CharacterController components, they are pretty slow compared to just modifying transform.position.

1 Like

Hey thanks Aron. That certainly helped me get the timing more accurate.