recast-navigation-js: Agent stuck in tiled navmesh

Using the following model with tile size of 32

scene (11).glb.zip

the agent get stuck at some point on the stairs

https://github.com/user-attachments/assets/657a9a08-f212-46d6-a7ac-7e83f6550c85

on C++ demo the agent is fine.

Did some debugging and seems the tile gen creates superficial connections between tiles on the stair and tiles below

Screenshot 2024-12-16 at 12 16 13

here the red poly is the clicked one and the green ones are the ones connected to it

on the C++ demo I used find local neighbourhood tool to show the connected polys

Screenshot 2024-12-16 at 12 51 43

so looks like the issue is on the js side

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

Found the issue!

It seems there’s a bug in the generators code, it’s confusing the unit of mesure for when we bake the navmesh with for when we create the detour navmesh data.

When we rasterize: height, climb … are in voxel units. cf https://recastnav.com/structrcConfig.html#a9b6bbabb4857e3f4bf4428af86ee7673

When we create navigation data they must be in world units . cf https://recastnav.com/structdtNavMeshCreateParams.html#a2ccf071ca70fe5566ddd2f214bac7779

the generators code is using voxel units for both. In here

https://github.com/isaac-mason/recast-navigation-js/blob/b5679037b877003ec2c59332d23df4d5f4e53a7e/packages/recast-navigation-generators/src/generators/generate-solo-nav-mesh.ts#L392

it’s just passing the recast value (in voxel units) to detour side which is expecting a wold units value. with a voxel unit of 0.2 for example A 1m climb height becomes 5 voxels so we’re actually creating a navmesh with 5m climb height

I think the confusion might’ve come from how units are handled in c++ demo vs in generators. In c++ demo GUI values for height, radius … are in world units, and are only converted when passed to recast side (https://github.com/recastnavigation/recastnavigation/blob/455a019e7aef99354ac3020f04c1fe3541aa4d19/RecastDemo/Source/Sample_SoloMesh.cpp#L397),

but otherwise passed as is to dtNavMeshCreateParams (https://github.com/recastnavigation/recastnavigation/blob/455a019e7aef99354ac3020f04c1fe3541aa4d19/RecastDemo/Source/Sample_SoloMesh.cpp#L702)

cc @isaac-mason

Hi @niko-dellic,

I haven’t looked into this deeply but can share this -

It seems the behaviour change is indeed related to the units fix for configs like walkableClimb, but I’m not sure the behaviour change is a bug.

Also worth mentioning that my general experience with off mesh connections is that they often need re-authoring when changing navmesh generation config.


I tried creating similar off mesh links using points returned from navMeshQuery.findClosestPoint and had no issues with that.

https://github.com/isaac-mason/recastnavigation/blob/599fd0f023181c0a484df2a18cf1d75a3553852e/Detour/Source/DetourNavMesh.cpp#L1024-L1050

{
    // old:
    // startPosition: {
    //   x: 56.09175491333008,
    //   y: 6.1955952644348145,
    //   z: -106.0022201538086,
    // },
    // new, picked with findClosestPoint
    startPosition: {
      x: 57.20161056518555,
      y: 6.3999924659729,
      z: -105.63432312011719,
    },
    // old:
    // endPosition: {
    //   x: 56.09175491333008,
    //   y: 49.945594787597656,
    //   z: -106.0022201538086,
    // },
    // new, picked with findClosestPoint
    endPosition: {
      x: 56.09175491333008,
      y: 50.239990234375,
      z: -106.0022201538086,
    },
    radius: 4.13,
    bidirectional: true,
    flags: 1,
    area: 1,
  },
Image

https://codesandbox.io/p/live/b847379f-3fba-49ba-baa1-eb3c839a6591

looking more closely at dtNavMesh::connectExtOffMeshLinks, it internally calls findNearestPolyInTile with the provided positions, and uses these half extents for the query:

const float halfExtents[3] = { targetCon->rad, target->header->walkableClimb, targetCon->rad };

https://github.com/isaac-mason/recastnavigation/blob/599fd0f023181c0a484df2a18cf1d75a3553852e/Detour/Source/DetourNavMesh.cpp#L473

I tried using the existing off mesh links you provided with an increased walkableClimb and off mesh links were created successfully:

Image

If there’s anything else you’d like help with it’d be great if you could set up a codesandbox like the one in my above message, saves a bit of time in creating a testbed 😃

Hope this helps!