Question on RecastJSCrowd's function agentGoto()

Hi guys,
I’ve been working on using RecastJS for navigation for a few days. Everything is fine except the agent mesh is always travelling in straight line even if there is obstacle.

In the image below, the red cover is visualized debug mesh generated by createDebugNavMesh(), you can see there is a non-walkable area showing under the obstacle building. The white line is generated using points provided by RecastJSPlugin.computePath(), which is correct.

However, once the agent mesh start to travel using agentGoto() function, it never follows the white path but goes straight to destination, as shown with black line I drew manually.

The thing that worked for me is when one agent mesh is about to collide with another agent mesh, they know to avoid each other.

Any thoughts about where should I look into? Everything works except this…

Many thanks!

Pinging el maestro @cedric

Hi @Jieling_Yang

That’s an interesting issue!

Did you create the crowd before computing the navmesh?
Can you repro the issue in a playground?

Hi @Cedric,

I did create the crowd before computing the navmesh. So I did a test by creating a simple box as obstacle then computing navmesh, and then creating crowd, it worked as you can see below.

However, when I switched back to use my own model, which is imported from a babylon file, it failed again. If I just use box, it works regardless the order of navmesh and crowd creation.

So obviously it’s related to the model mesh, my bet is it has something to do with the timing of BABYLON.SceneLoader.ImportMesh. I did put all calculation code in its onSuccess callback though.

I say this because I experienced some weird problem before, that when I manipulate and then check some data of imported mesh inside onSuccess of ImportMesh, say mesh position, I get correct value, but if I pass that manipulated position to another function (called within onSucess) and then check, the value is different and act like it’s never been changed. It was very minor to me and I had very easy workaround so I didn’t pay much attention. But this reminds me of it.

Sorry that I can’t create a playground for this, at least not quick enough because there are quite some ground work I need to code inside the playground…

Anyway, thank you very much, I got the direction to keep digging now :smile:, and also thank you @Deltakosh for calling the help.

If you do a small .babylon scene to repro the issue I can take a look if you want.

Hi Cedric,

I found out how to solve it.

I was creating the playground for it and when I wrote the code for importing mesh, I realized that there are some code I didn’t put them into onSuccess callback of ImportMesh. Unfortunately because of the structure of my code, I couldn’t. That leads to my original problem.

I probably should give you the big picture for the problem: What I’m trying to achieve is that dynamically placing “buildings” which are treated as non-walkable area for “characters”. With desired building type selected, every click on the ground mesh, the building model is “placed” at clicked position. My old code was trying to import the building mesh with each click. The fix is that I loaded building meshes during setup stage and make them invisible, when the time comes to place one of them, I use mesh.createInstance() instead of importing to create the building mesh.

Also, I need to correct what I said earlier that the order of navmesh and crowd creation doesn’t matter - It matters. Navmesh needs to be computed first.

I can’t upload a video so I just did some screen shots for a working demo :):grin:
As you can see I created a bunch of characters, then added two buildings, and in the last image you can see one character is following the white path.

Thanks again!

Creating characters

Creating buildings

Creating buildings

Walking among buildings

1 Like