Hey I'm creating my game with DOTS and I don't manage to add a proper agent avoidance.
Considering standard NavAgents aren't available under ECS I tried many options to get a result, physics based avoidance, raycast, ...
The main Issue is that in each case my agents leaves the NavMesh.
I was wondering if anyone have some solutions for that?
I also searched for some other pathfinding algorithms like BOIDS but I haven't find how to do it with the NavMesh.
#DOTS Navigation with avoidance
1 messages · Page 1 of 1 (latest)
Do you mean avoidance is pushing characters off the navmesh?
Yeah
so the /easy/ solution is you need to move using navmesh so you can never escape it
normally physics colliders would stop you escaping but if you don't use physics then you need to walk along the navmesh
not sure what navmesh solution you are using, but recast, which is what most libraries use under the hood (unity/unreal) have a method called MoveAlongSurface
which I think is this api for unity
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/AI.NavMeshAgent.Move.html
now this does mean that your avoidance + movement are fighting
your avoidance has no idea about your navmesh bounds so might try push it out and your navmesh prevents it so you can get into a bit of a stuck loop in tight spaces
the hard solution is you need to include your navmesh inside your avoidance - the edge of the navmesh is something that should also be avoided
for me, i use orca (more commonly referred to as rvo2) for my avoidance which uses velocity lines
so apart from adding a velocity line for all agents, i generate polygones for the edge of the navmesh and pass in the nearby segments of these as velocity lines
this way my creatures also avoid the edge and play nice
now this isn't easy
i hacked away at this for 2 years before getting it working how i wanted (though a lot of this was building my own navmesh api for entities)
and tbh it isn't needed for most games, moving along navmesh (rather than just setting transform) is good enough for most games
at least with clever design
I checked that part but the code isn't accessible.
Is there a way to "override" the default class and implement it under ECS?
yeah my issue was basically unity internals of recast are all hidden / inaccessible
so i wrapped and reimplemented the whole thing recast library
took so long 
How do you even do that?
recast (+ detour) is a public library
it's what both unity + unreal navmesh solutions are based on
(though as unity's implementation is within the engine, it's unknow what if any modifications they've made)
and are there any samples on how to re-implement it?
no
it's a huge job, don't recommend 😄
unless it's something you really want to do
The thing is that the navmesh works well under ECS but I'm missing that avoidance I'm looking for.
And I haven't found any suitable solutions.
i personally use https://gamma.cs.unc.edu/RVO2/
this one is a lot easier to implement
there are probably good alternatives
ok I see, but this problems will appear again I guess, how do you ensure Agents stays on the navmesh while avoiding each others?
main reason i wrote my own navmesh was so i could get the raw data and generate a polygon around the edge
^ then i do this
😭
but it's not needed, i've done this without that
and yeah i just use the move method instead of setting translation so it can never leave the navmesh
the move method wdym?
Unity AI one ?
I'll try that and give some updates about how it's going
I would recommend the Agents Navigation package, it works pretty much out of the box with native Unity navmesh and entities https://assetstore.unity.com/packages/tools/behavior-ai/agents-navigation-239233
Hey, I just tried this one, but it does not seems to handle 3d worlds 🤔
it does, there's a 3d version https://gamma.cs.unc.edu/RVO2/downloads/
RVO2 Library - Reciprocal Collision Avoidance for Real-Time Multi-Agent Simulation
you don't really need 3d though unless you're a space ship kind of game
most '3d' games still only collide along the xz planes
and you can handle floors of buildings etc by filtering by the y plane on the nearest neighbours
I found another solution with this package :
https://github.com/ikpil/UniRecast
Has anyone ever used it, I haven't found any documentation on how to use it?
Like how to create an agent and move it on the navmesh etc...
Cool package but won't work in burst as they've unfortunately wrapped managed
ok I see, but I'm still a bit confused on how I am supposed to handle heights with RVO2.
I have a game with multiple floors and at each floors you can climb on obstacles.
How should I proceed?
Filtering by Y plane as you said I guess, but I don't really see how to handle that.
Do I need to create a navmesh per height or something like that?
navmesh works fine for this
here sec
// The agents cannot collide if they are on different y-levels.
// Also do not avoid the agent itself.
// Apply the layer masks for agents.
var isNeighbour = neighbour != agentIndex &&
math.min(localElevation + agent.Height, otherElevation + otherAgent.Height) >= math.max(localElevation, otherElevation) &&
(agent.CollidesWith & otherAgent.Layer) != 0;```
this is what i do
ignore agents that y + heights don't overlap
ok I see, and do you also handle slopes?
navmesh handles slopes
navmesh works on stairs/steps and everything
oh yeah I thought we were speaking about the navigation with RVO2 my bad.
I'll try to get something working and reach back thanks.
ok so I managed to get RVO2 working with UnityNavmesh.
I was wondering if you could give me some tips on how to "dynamically" insert navmesh bounds into RVO2 and how to setup thoses velocity lines?
I'm a bit lost on how I should proceed.
I've saw that I can use NavMesh.CalculateTriangulation to get the data I need from the Navmesh but I was wondering if I should create obstacles based on this data or modify the RVO2 calculations to include theses lines.
sorry to bother you once again.
Could you give me a bit more informations about how you do that?
Extracting the navmesh triangle is easy with one function, but how do you get the edges 🤔?