Thinking of buying Pro; few questions about differences from Unity's NavMesh (and my struggles)

Hi,

I am working on a ARPG game (Diablo style), indie dev. So I need pathfinding for player character and for some monsters at the same time - haven’t thought much about it, but it can be optimised to have less than 100 agents on the move (maybe even less?).
Until now I used Unity’s NavMesh system with mixed results (disclaimer: there might be some things that I am not aware of; will gladly accept advice/hints). My issues specifically:

  1. Avoidance between player and monsters.
    Unity’s NavMeshAgents have obstacle avoidance priority. If I put the player as higher priority, it can push monsters around (not ok). If I put monsters as higher or equal priority, they can push the player around (very not ok).
    I “solved” this with some “hack” where a monster has both NavMeshAgent and NavMeshObstacle components, and swapping between them whether the monster is in range of player or not. While this is partially ok, it still has two issues: if a monster tries to run away from the player, I have to do it by hand (didn`t even try); and if a large pack of monsters are trying to get in (melee) range of the player, the ones in the back are stuck running because they can’t reach the player (I can probably fix this, but it all feels bad).

  2. Player randomly slowing down near edges.
    This happens even without any monster around, so just the player and a baked NavMesh (no moving obstacles, no fancy stuff). I just put a few cubes and set them to “Not Walkable”, bake the NavMesh, and when the player runs around a cube, sometimes it slows down.
    https://imgur.com/a/BxiIKmu - this should explain it better than my words.
    Note that “Auto braking” is not set.

  3. Problems with generating NavMesh in complex levels.
    If I generate NavMesh on a plane with a few cubes, it ends up ok. However, on the more complex levels (some asset packs I bought), there are issues with the generation when it comes to elevations and obstacles. Some areas that should be walkable ended up not-walkable, vertical hops leading to janky movement, obstacles “eating” way too much from the walkable area, and so on. I understand that some of the issues might be due to the meshes/colliders in the models themselves, but I couldn’t tweak it at all, it was just “keep changing settings, maybe add few more colliders, and rebake until it ends up good”.

From my point of view, 1 and 2 are unacceptable. 3 I can work with, it’s just a lot more work on my side, so I’d preferably avoid that too.

I apologise for writing a long post which is more about Unity NavMesh rather than A*. I would like to know if I will encounter these issues after purchasing the pro version. I tried the free version, but without being able to generate a NavMesh, I couldn’t make it work.
I would like a pathfinding solution where I feel “in control” and character control is smooth - that is my top priority. The game is aimed for PC so at this stage I am not worried about FPS, and I think that the number of active agents can be easily cut down to <100 (is that few? many? average? I feel a bit clueless).

Thank you

Hi

I’m glad you are considering my package.

  1. In my package local avoidance agent’s have both a local avoidance layer (separate from unity layers) and a mask of other layers that they avoid. They also have a priority field which will make them care/not care about other agents (similar to unity’s priority). So if I understand you correctly, you want the monsters to have local avoidance between the different monsters, and you want the player to not be able to push around monster, but monsters shouldn’t be able to push the player around either? This is a bit tricky because the local avoidance algorithm (RVO) that both my package and Unity’s navigation system uses does not make a distinction between pushing around and stopping because there’s an obstacle in the way.
    In diablo the player (as far as I can tell) does not seem to have any collision with enemies (except large ones that are more like obstacles).
    It is possible with some minor tweaks to the code however to make it so that the enemies would appear to be unmovable agents from the player’s point of view and the player would appear to be an unmovable obstacle from the enemies point of view. Though it’s possible that this could still lead to some slight pushing behavior (I haven’t tried it).
    Making the player be able to pass through enemies (or only use local avoidance with other ally units) is however very easy to do.

  2. This is also due to the local avoidance algorithm, in my package this is controlled by a parameter on the RVOController called ‘obstacle time horizon’. Essentially the RVO algorithm ensures that the agent would not collide with an obstacle for that amount of time if it continued on its current trajectory, so a large-ish value could make it slow down unnecessarily near edges because it really wants to avoid colliding with them. For your player I think you could make that value quite low.

  3. It’s hard to say how this will work in my package as I don’t know what exact issues you were having. My package does have a lot more knobs to tweak the navmesh generation process however. It sounds like the resolution of the graph was too small though.

100 agents should not be any problem to handle. You may in the future want to write a custom movement script instead of using the ones that are included in the package to get maximum performance out of it though (the included movement scripts have to cater to many different types of games and have many options and features that may be completely unnecessary for your game, making a custom movement script specifically for your game could allow you to get better performance).

Thank you for your fast reply.

Got the package, now it is time for the learning curve. I went straight with the custom movement script (as I already “kinda” had those), hoping I didn’t bite more than I could chew.

I’m sure I will have some more questions as I experiment stuff, another topic perhaps. I will still update here my findings specifically related to points 1,2,3.

Hi

Sounds good!
You might want to start out with the built-in movement scripts though, especially if you are going to test local avoidance. The tutorial for writing a custom movement script is very basic.

I will humbly ask for help on this one, didn’t have much success myself.
I chose to use RichAI for monsters, and a custom script (which is 95% the one from the tutorial) for the player.
The monsters avoid eachother nicely, which is good, but they also make room for the player, which is what I expected. I tried adding “RVO Square Obstacle” to the mobs (similar “hack” to what I did with Unity NavMesh), but the path goes straight through the obstacles.

I think that I can avoid monsters pushing player if I force-stop them when they get in “attack range” (which will be a bit larger than collision distance). This is already in place, and the monsters only push each other (but not the player) when they all try to get around the player (there is room for only a few).
So I think I need the player to treat monsters as obstacles (at least the close-range monsters).

Hi

Okay, so the change you will have to make is something like this:

Open the RVOAgent.cs script and find the line that looks like

if (other.locked || other.manuallyControlled) {

and replace it with

if (other.locked || other.manuallyControlled || other.layer != layer) {

and add a new line right below this line

Vector2 otherOptimalVelocity = Vector2.Lerp(other.currentVelocity, other.desiredVelocity, 2*avoidanceStrength - 1);

that looks like

if (other.layer != layer) otherOptimalVelocity = Vector2.zero;

Then on the RVOController component, make sure the player has a different local avoidance layer than the enemies. With this change, the enemies will think the player is unmovable and static, and the player will think the same thing about the monsters.

I have not tried this change myself, but I think it should work reasonably well.

The RVOSquareObstacle is only for local avoidance, it does not impact pathfinding at all (neither will the above change).

Hi,

Sorry for the delayed response, didn’t have too much time to play with things lately. However, it works!! Thank you VERY much!

1 Like

Awesome! I’m glad it works well for you!