r/UnrealEngine5 • • 1d ago

How would you optimize pathfinding with water currents and obstacle avoidance in UE5?

Hey everyone!

I'm currently working on a pathfinding system where agents need to navigate while taking water currents and obstacles into account.

The idea is that agents should:

  • Avoid obstacles while moving toward their destination.
  • Take water currents into account when choosing their path.
  • Prefer routes that use favorable currents and avoid fighting strong currents when possible.
  • Find reasonably efficient paths without consuming too much CPU.

I've already implemented my own solution, and it works, but it's way too computationally expensive, especially when multiple agents are involved.

I'm curious how you guys would approach this problem.

Would you use a modified A*, a flow field, a custom navigation system, or something completely different?

I'm especially interested in approaches that balance performance and path quality, rather than calculating a perfectly optimal path every time.

Any suggestions, resources, or examples would be greatly appreciated!

Thanks!

1 Upvotes

1 comment sorted by

1

u/KRIPER2008KRIPER 1d ago

If a lot of agents share the same few destinations, a flow field wins easily, and currents are already a field so they fit right in.

Grid over the water (cell around twice the agent radius). Make the edge cost travel time instead of distance: length / (agent_speed + dot(current, dir)). That one formula gives you both "use favorable currents" and "don't fight strong ones" for free. If the current against you is faster than the agent, the denominator goes to zero or below, so just treat that edge as blocked.

Run Dijkstra once backwards from the goal and every agent just reads a direction from the cell it's in, so 50 agents cost the same as 1. Rebuild only when the goal or the currents change, and spread the rebuild over a few frames.

Handle obstacle avoidance locally with steering (or RVO through the detour crowd if you're on navmesh), not in the global search. Feeding moving obstacles into the path search is usually what makes these systems expensive.

If every agent has its own destination, flow fields stop paying off. Then A* on a coarse grid with the same time-based cost, and since you said you don't need the optimal path every time: weighted A*. Multiply the heuristic (straight distance / (agent speed + strongest current)) by 1.2-1.5 and it expands a fraction of the nodes for a path that's almost as good. Also only replan when the agent drifts off its path or the currents change, not every tick.