# Navmesh not taking shortest path

**URL:** <https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377>\
**Category:** Questions\
**Created:** [April 30, 2023, 6:51pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377 "2023-04-30T18:51:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![keg](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keg](https://forum.babylonjs.com/u/keg)\
**Post date:** [April 30, 2023, 6:51pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/1 "2023-04-30T18:51:43Z")

</div>

Hi I’m struggling with my AI not taking shortest path(see img), I guess its my navmesh properties that are not right, any advice on how to fix this? Thanks in advance 🙂

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/f/7f15bd4d0183af33fd2e402b04ad1d981ce7c03a.png)

Playground:

> **[Babylon.js Playground](https://playground.babylonjs.com/#TN7KNN%23478)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![keg](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keg](https://forum.babylonjs.com/u/keg)\
**Post date:** [April 30, 2023, 11:24pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/2 "2023-04-30T23:24:59Z")

</div>

Update: in the original example I used several cubes, but when I test with only one long cube it finds the shortest path…  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/9/59109bc0d4f8cf49746e425431ffb5b48f6fbdb8.png)

---

<div class="post-metadata">

**Author:** ![CodingCrusader](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/codingcrusader/32/29857_2.png) [@CodingCrusader](https://forum.babylonjs.com/u/CodingCrusader)\
**Post date:** [May 1, 2023, 11:20am UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/3 "2023-05-01T11:20:22Z")

</div>

I can recreate the problem, but have no idea how to fix it. Alternatively, I would suggest using a library that can find the shortest path between two points in a maze:

[PathFinding.js (qiao.github.io)](https://qiao.github.io/PathFinding.js/visual/)

---

<div class="post-metadata">

**Author:** ![keg](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keg](https://forum.babylonjs.com/u/keg)\
**Post date:** [May 1, 2023, 1:59pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/4 "2023-05-01T13:59:31Z")

</div>

thanks will check it out 👍

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [May 2, 2023, 2:41pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/5 "2023-05-02T14:41:20Z")

</div>

cc @Cedric

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 2, 2023, 3:41pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/6 "2023-05-02T15:41:41Z")

</div>

This is a weird behavior I can’t explain. I guess it’s the multiple boxes that create extra triangles in the navmesh. Hard to say without a c++ repro and debugging.

---

<div class="post-metadata">

**Author:** ![Joe\_Kerr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/joe_kerr/32/39017_2.png) [@Joe\_Kerr](https://forum.babylonjs.com/u/Joe_Kerr)\
**Post date:** [May 2, 2023, 4:52pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/7 "2023-05-02T16:52:14Z")

</div>

Maybe be related and if so would be a known problem with Recast (not Babylon). See here [Not direct path in some situations · Issue #239 · recastnavigation/recastnavigation · GitHub](https://github.com/recastnavigation/recastnavigation/issues/239) ☹

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 3, 2023, 8:14am UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/8 "2023-05-03T08:14:14Z")

</div>

A workaround is to have less nodes to traverse.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/c/cc1a014ce0e989b495a6cb917debfcdb2c52cc33.jpeg)  
I think it’s possible to fix it by increasing navmesh simplification. It will give a more uniformly tesselated mesh and a\* will work better.

---

<div class="post-metadata">

**Author:** ![keg](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@keg](https://forum.babylonjs.com/u/keg)\
**Post date:** [May 4, 2023, 3:38pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/9 "2023-05-04T15:38:22Z")

</div>

thanks 🙂 by any chance, what settings did you use?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 4, 2023, 3:48pm UTC](https://forum.babylonjs.com/t/navmesh-not-taking-shortest-path/40377/10 "2023-05-04T15:48:55Z")

</div>

I didn’t find a good method that works well and for sure.  
But, a good start is to have a good `minRegionArea` and then tweak other values. It seems removing small area where agents can’t go, simplifies the geometry substancialy.  
Best is to tweak the input geometry in this case.
