Navigation Mesh and crowd Agents

@Cedric
When box start acceleration work as should, but when it is near finish point then it slowly down his speed. Maybe acceleration should work for start/stop not only for start

@Gijs helped me with movement implementation along path, which is generated using navMesh. Movement working perfect, but now i find problem in avoiding dynamic objects during moving. Your code in Crowd agents implement that. I trying adjust parameters of agents, but i cannot achieve constant speed.
There is PG with constant speed along path: https://www.babylonjs-playground.com/#X5XCVT#20
Do you have how can i achieve that using crowd agents?

Hey @Cedric,

Would it be possible for us to import an already existing navmesh and use it? If not, would this be a viable addition to the navigation mesh? I find it quite useful being able to build a navmesh in blender or anywhere else and being able to use it.

Saving/loading the computed navmesh is possible. Iā€™m waiting for some users before adding that feature.
But the navmesh is not just a collection of triangles. it also contains information on connections used by the crowd system. Injecting a mesh into the navigation might be feasible but itā€™s not the normal use.

Anything more complex than the computed straight path (catmull curve for example) must be done by the user. The PG you provided is a good example. As usual, it depends on what you want to achieve. For a racing car game, the navmesh computed path becomes a suggestion for the AI and the physics. You donā€™t follow the path, you try to follow it.
Maybe you can do the same with crowd: compute catmull path for agents, then ask the agent to go to the nearest path point. This can work depending on the number of agents and frequence of collision avoidance.

Constant speed might be an issue with collision avoidance. If agents canā€™t break slowly. Can you tell me more about your use case?

SHi @sebavan, independently from UMD vs ES6, how would we go about importing recast from node_modules using import / require? Iā€™m currently importing it from https://preview.babylonjs.com/recast.js using a script tag in my html file, but would prefer doing that in my js code (for offline usage among others).

Cc @kvasss if thatā€™s what you want.
Cc @Cedric in case you know :).

Thanks for the in-depth look at my question. I have quite a big terrain for which i am not able to build the navmesh in real-time.

I am currently using the external navigation mesh plugin for BABYLON which I have also optimized . GitHub - wanadev/babylon-navigation-mesh: A library to move on navigation mesh with BABYLON.js . This works with an external navmesh build somewhere else and imported in BABYLON.

However, the accuracy isnā€™t the best, I think recast has a better one so I was opting to change. I guess I will stick with the old plugin for now, thanks for the answer.

I guess we need to push recast somewhere as part of the package, it could simply be in on a different path ???

So that everybody could import it.

Any thoughts ?

Somewhere as part of the package sounds good. Or it could be in its own package, a bit like how we import pepjs or earcut for example. I would guess the second option keeps the core package smaller and would be better (?)

@deltakosh any preferences ?

yeah we should do the same as earcut

@tibotiber and @Cedric , would you mind checking with the recast team if they are interested in publishing their lib to npm ? If not we ll only be able to embed.

Maybe @Cedric will be able to publish it \o/ Let s see how this works.

From what I understood in my previous conversation with @Cedric, the recast JS wrapper is implemented on our side at Extensions/recastjs at master Ā· BabylonJS/Extensions Ā· GitHub. Seems it would be the place to publish from. What do you think?

Iā€™m curious, how are extensions releases managed? Is it mapped to core or at their own pace?

Yep! Iā€™ll publish from that repo.

2 Likes

I just published recast-detour on npm


This is my first npm so I may have missed something. Let me know if something should be fixed ! :slight_smile:

4 Likes

GG GG GG \p/

1 Like

This is great, thank @Cedric. Iā€™m now using it this way:

import { RecastJSPlugin } from '@babylonjs/core/Navigation/Plugins/recastJSPlugin'
import Recast from 'recast-detour'
const navigationPlugin = new RecastJSPlugin(Recast)
[...]

Just 2 small improvements maybe:

  1. You could add the repository field to your package.json, that will let npm automatically link the module to the repo in their interface.
  2. After I import Recast like this, Iā€™m getting a new warning. Everything works though.
    In Chrome: recast.js:2356 - Invalid asm.js: Undefined global variable
    In Firefox: recast.js:2356 - TypeError: asm.js type error: 'undefined' not found in local or asm.js module scope

Let me know if I can be of any help on that warning, not sure where to start tbh.

Congrats on your first npm package :wink:.

1 Like

The repo only contains the source and not the compilation result recast.js. Is it a problem if I add it anyway to the package?

If Iā€™m not wrong itā€™s just a piece of information with no behavior attached so thatā€™s fine. Double checked at npm-package.json | npm Documentation and it seems itā€™s just that yes. Note that you can put in the directory as well since youā€™re in a monorepo setup (last part of the link above).

1 Like

@Cedric
Sorry for replay after few days, but I was off.

https://playground.babylonjs.com/#CYS4N4#4 There is PG with my problem. Blue boxes are enemies and red is player. They are fighting. For some reason new enemy called enemy4 want to attack player, but it cannot attack from the front, because others enemies (1,2,3) are there. On the right side is one enemy (5), so last called enemy4 should go to left side and attack player. I try to tuning parameters to achieve constant speed for player and enemies. Also I want to avoid slowly decreasing speed where box is near target point.

Hi @FurcaTomasz

In your playground, the enemy 4 goes on the left to attack player. The path is shorter to the player. Do you get another behavior?

The slow decrease in speed when the enemy is near the player might be caused by the collision response between enemy 4 and the player. You ask the enemy to go where the player is. So heā€™ll try to take his position. Try to compute a destination position around the player within a radius corresponding to the sum of enemy radius and player radius. So the enemy will stop before reaching him. Then, increase the maxAcceleration value so the acceleration and deceleration curves will be steeper.