Local Avoidance 3.0.0

Hey,

So almost 8 years ago I started creating my very first RTS Game on Unity. It was really a blast and I managed to recreate very close experience of Warcraft 3 on Mobile

.

For agent avoidance I used Unity built-in navmesh agents. However I quickly noticed that it does not perform that well in most critical RTS cases (etc. circling targets, getting around standing agents). I decided maybe I should try to roll out my solution, it should not be that hard, is it? Boy… I was wrong… Not long I realized outside RVO solution, many successful companies tend to not share their navigation tech (Maybe things did change now). I remember spending many hours dissecting one of the GDC videos where blizzard employee was show-offing their local avoidance, but leaving all details unexplained :smile:. Finally, I came up with cool solution…

Fast forward to now, sadly project did not reached the daylight for various reasons. Yet I noticed there is a lot of value in my custom local avoidance solution. So I decided to create a package out of it using even more powerful algorithm with DOTS.

For version 2.0.0
I released complete minimum API so it could be fit into any design with ease, regardless it is OOD or DOD. Here is small example with one obstacle and drawing it in gizmos:

void OnDrawGizmos()
{
    using (var sonar = new SonarAvoidance(transform.position, quaternion.identity, InnerRadius, OuterRadius, math.length(Velocity), Allocator.Temp))
    {
        sonar.InsertObstacle(new float3(-1, 0, 0), math.radians(180));
        if (Obstacle)
        {
            sonar.InsertObstacle(Obstacle.transform.position, ObstacleVelocity, ObstacleRadius);
            sonar.DrawObstacle(Obstacle.transform.position, ObstacleVelocity, ObstacleRadius);
        }
        sonar.DrawSonar();
        sonar.DrawClosestDirection();
    }
}

This solution end up exhibiting many cool behaviors like:

  • Manages navigation out of concave obstacles
  • Circles target
  • Avoids head to head moving
  • Accurately respects radius
  • Predicts collisions and avoids based on that
  • Avoids only when necessary

Some of them can be seen in:

To honor the Starcraft2 I even recreated Zerg demo:

In Bigger crowd:

Finally, decided to bring back new solution to my Old game and see how it works :smile::

Package AssetStore
Support Discord
Demo Zerg

Now for version 3.0.0
I plan to create some MonoBehaviour implementation so there would be possibility to use package without coding. I am currently fixated on idea having MonoBehaviour as wrapper and behind the hood running ECS in hybrid mode. This would allow code to work with other MonoBehaviour components and also having all advantages of ECS. Also as bonus this enables easy way using ECS only for those who would want. I am curious to hear other opinion about this approach, as this would require having ECS in your project.

To give better idea here is the scene with 10 agents. Each agent GameObject has its copy of Entity as seen in Entity Debugger. Their settings gets in sync.

Here is image with Entity selected.

That is kind a it, thanks for taking interest.

13 Likes

Oooh, ECS-only would be awesome. Looking forward to 3.0.0))

2 Likes

Recreating now test scenes with new systems. Will keep them as benchmark across the development. There is still some overlaps, but that will be improved. 8250339--1079625--Hallway.gif 8250339--1079598--CircleTarget.gif 8250339--1079601--GroupExchange.gif 8250339--1079607--EscapeConcaveJail.gif

1 Like

Design coming together really nice.

Here is example where monobehavior agents gets converted to entity and still syncs transform.
8250384--1079631--CreateAgent.gif

Solution is very modular and you can replace any behavior easily. Like gif shows firstly it has no avoidance and goes through the obstacle. In other plays to different avoid algorithms are used.
8250384--1079634--Avoid.gif

The same design will allow for adding/removing with ease other components like unity navmesh, flocking, agent shapes, 2d/3d, different movement algorithms or even implementing other package navigations like A*.

2 Likes

Awesome, I think performance is key.

1 Like

i like it !!!
is there a roadmap?

1 Like

For now there is not much of the roadmap.
Version 3 is set to include:

  • Hybrid/ECS agent implementation
  • Version 2 avoidance component
  • ORCA component
  • Jobified Unity NavMesh component
  • Few shapes for obstacles (Capsule for 3D, Circle for 2D and probably some polygon for non moving)
  • Flocking (Not sure about this one yet)
    The whole focus will be to have very modular and high performance solution for agents.
1 Like

K seems like ECS unity navmesh works now :O! It uses UnityEngine.Experimental.AI. 8265396--1082358--NavMesh.gif

Also auto repath works in case obstacles added that carves navmesh.
8265396--1082361--NavMeshRepath.gif

So far really happy about how it goes. Fully multi-threaded and still work with unity builtin navmesh, that is crazy.
Will do stress test on this later.

7 Likes

Looks awesome! I’m searching for some good dots based pathfinding and local avoidance system right now. Your is looking very promising. Does version 3.0 still under development?

I am back at developing it. Was a bit sidetracked by my other asset store packages.

Here is overview of current progress:

  1. Implement Agent, Agent Capsule Shape components. Which allows simple agent movement (Done Before)
    8498078--1131320--Movement.gif
  2. Implement Agent Collider, Agent Separation components. Which allows distance enforcing between agents (Done Before)
    8498078--1131323--Collider.gif
  3. Implement Agent Avoid component. Which enables local avoidance using this package (Done Before)
    8498078--1131329--Avoid.gif
  4. Implement Agent Navigation component. Which allows agent to use Unity NavMesh (Done)
    8498078--1131326--NavMesh.gif
  5. Upgrade from ECS 0.5 to ECS 1.0 (Done)
  6. Implement Agent Circle Shape for proper 2D support (Not Started)
  7. Sync GameObject properties to Entity (In Progress)
  8. Change most of the systems from SystemBase class to ISystem interface. This will reduce main thread overhead even more (Not Started)
  9. Huge zerg demo, with ground small zergs and flying zergs (Not Started)
  10. Cache NavMesh requested paths. As example if huge groups requests path, in theory they all can reuse same path (Not Started)

This solution will be designed to work with both Entity and GameObject. In Entity case you will use usual ECS workflow of baking. Where with GameObject, there will be internal ECS world syncing with GameObjects.

1 Like

As I haven’t started huge zerg demo. For now got performance numbers with 60 agents GameObjects.
There is still place for optimization, but so far not bad. Overhead on main thread is 0.12ms, avoid job 0.06ms, collider jobs 0.2ms, 0.155ms navmesh update.
So far biggest performance offender is collider jobs as they are not scheduled parallel and requires 4 iterations.

1 Like

This is really cool I’ve been looking for something like this for ages in DOTS. I tried making my own, but like you say its really bloody hard.

1 Like

Managed to make collider job also parallel. Now made initial stress test demo (Going to look better in the future :smile:).
8510501--1133966--More.gif

It is still not many agents roughly ~2k. However impressive part is still GameObjects that are driven by internal ECS world.


Green blocks bursted navigations jobs, as you can see most cost comes from Game Object Skinned mesh, rendering and others.

This demo does not uses SonarAvoidance jobs, only NavMesh and Collision jobs.

3 Likes

Would it be possible to prevent agents from pushing each other?

Awesome work, this looks really efficient!

Yes, plan to provide mask probably

I have a dumb basic question that probably is answered somewhere, but does this work without the navmesh I have my own flow field navigation system I want to use this with.

Yes, if you would check the gifs above carefully ( https://discussions.unity.com/t/885824/10 ), you will notice that each of them are with different components combination, first one does not even have navmesh. Idea is that you would combine components to have desired behaviour and everything will be modular.

1 Like

That’s awesome, thanks.

1 Like

Looks excellent, good work!

1 Like