Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(nav): pass occupied intermediate grid waypoints safely

yhh82c23024951b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4af072798..d9ed03787 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@ published separately; it ships inside the editor.
## [Unreleased]
+### Fixed
+
+- **Couriers can pass occupied intermediate grid waypoints.** A parked agent no longer traps a follower at an intermediate cell centre. The follower may join the next route segment only when its full body fits the connection through the static grid; final destinations still use the existing arrival rules.
+
## [0.87.0] - 2026-10-15
### Fixed
diff --git a/sdk/src/ai/nav/NavPlugin.ts b/sdk/src/ai/nav/NavPlugin.ts
index a12197b1b..c35d822a9 100644
--- a/sdk/src/ai/nav/NavPlugin.ts
+++ b/sdk/src/ai/nav/NavPlugin.ts
@@ -447,6 +447,15 @@ function walkAmongBodies(
flat: boolean, neighbours: AvoidanceNeighbour[], nav: Navigation,
): boolean {
const pos = tf.position;
+ // Intermediate cell centres may be occupied by a parked body. Join the
+ // following segment only if the whole body fits; never skip the final goal.
+ const waypoint=rt.waypoints[rt.index];
+ if(waypoint && rt.index+1<rt.waypoints.length
+ && neighbours.some(n=>Math.hypot(n.x-waypoint.x,n.z-(flat?waypoint.y:waypoint.z))<agent.radius+n.radius)
+ && nav.surface instanceof NavGrid && nav.surface.isNavigable(pos,{radius:agent.radius})
+ && gridMoveFits(nav,pos,rt.waypoints[rt.index+1]!,agent.radius)) {
+ rt.index++;rt.recoveringStart=false;
+ }
while (rt.index < rt.waypoints.length) {
const wp = rt.waypoints[rt.index]!;
const reach=rt.recoveringStart && rt.index===0 ? 0.1 : Math.max(agent.speed*dt*1.5,WAYPOINT_REACH);
diff --git a/sdk/tests/nav-courtyard-delivery.test.ts b/sdk/tests/nav-courtyard-delivery.test.ts
new file mode 100644
index 000000000..08fe418df
--- /dev/null
+++ b/sdk/tests/nav-courtyard-delivery.test.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: Apache-2.0
+import {it,expect} from 'vitest';
+import type {Entity,Vec3} from '../src/types';
+import {Transform} from '../src/ecs/component';
+import {NavAgent} from '../src/ai/nav/NavAgent';
+import {NavGrid} from '../src/ai/nav/NavGrid';
+import {Navigation} from '../src/ai/nav/Navigation';
+import {stepNavigation,type NavWorldView,type AgentRuntime} from '../src/ai/nav/NavPlugin';
+import {applyObstaclesToGrid} from '../src/ai/nav/navObstacles';
+
+it.each([1/60,1/50,1/120,1/30,1/15,1/10])('delivers an eight-agent courtyard around a warehouse at dt=%s',dt=>{
+ const grid=new NavGrid({width:23,height:13,cellSize:32,origin:{x:-352,y:-192}}),nav=new Navigation();
+ for(let y=0;y<13;y++)for(let x=0;x<23;x++)if(x===0||x===22||y===0||y===12||(x===11&&(y<5||y>7)))grid.setWalkable(x,y,false);
+ applyObstaclesToGrid(grid,[{center:{x:-160,y:0,z:0},halfExtents:{x:46,y:46,z:32},rotation:{x:0,y:0,z:0,w:1}}]);
+ nav.setSurface(grid);nav.planningBudgetMs=0;
+ const entities=Array.from({length:8},(_,i)=>(i+1) as Entity);
+ const data=entities.map((_,i)=>new Map<string,unknown>([
+ ['Transform',{position:{x:-288+(i%3)*32,y:-96+Math.floor(i/3)*32,z:0}}],
+ ['NavAgent',NavAgent.create({speed:78,radius:8,arriveRadius:5,repathInterval:0,hasTarget:true,targetX:64+(i%5)*64,targetY:-128+Math.floor(i/5)*64})],
+ ]));
+ const world={getEntitiesWithComponents:()=>entities,has:(e:Entity,c:{_name:string})=>data[e-1].has(c._name),
+ get:(e:Entity,c:{_name:string})=>structuredClone(data[e-1].get(c._name)),
+ set:(e:Entity,c:{_name:string},v:unknown)=>{
+ if(c._name==='Transform'){
+ const pose=v as {position:Vec3};
+ for(const axis of ['x','y','z'] as const)pose.position[axis]=Math.fround(pose.position[axis]);
+ }
+ data[e-1].set(c._name,structuredClone(v));
+ }} as NavWorldView;
+ const runtimes=new Map<Entity,AgentRuntime>();
+ for(let i=0;i<Math.ceil(15/dt);i++){
+ stepNavigation(world,nav,dt,runtimes);
+ for(const e of entities)expect(grid.isNavigable(world.get(e,Transform).position,{radius:8})).toBe(true);
+ }
+ const state=entities.map((e,i)=>({agent:data[i].get('NavAgent'),pose:data[i].get('Transform'),runtime:runtimes.get(e)}));
+ expect(state.filter(s=>(s.agent as {arrived:boolean}).arrived),JSON.stringify(state)).toHaveLength(8);
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index fe56cf11b..1ba38130b 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(nav): pass occupied intermediate grid waypoints safely':
+ { note: 'Couriers can pass occupied intermediate grid waypoints.' },
'test(nav): cover authored workshop obstacle layouts':
{ internal: 'Headless exported-workshop acceptance also loads a scene with authored obstacles enabled and verifies retained state and delivery after reopening.' },
'chore(release): classify v0.87 feature verification':
diff --git a/tools/verify-navigation-workshop.mjs b/tools/verify-navigation-workshop.mjs
index 496ca2192..54e9a0130 100644
--- a/tools/verify-navigation-workshop.mjs
+++ b/tools/verify-navigation-workshop.mjs
@@ -78,7 +78,7 @@ try {
if(distance<8-0.001)overlaps.push({frame:i,name,x:p.x,y:p.y,distance}); }
if(i%10===0)trail.push(at['Courier 07']);
}
- return {trail,overlaps,maxPenetration,contactTolerance:0.001,facts:host.facts()};
+ return {trail,positions:host.probe(names).at,overlaps,maxPenetration,contactTolerance:0.001,facts:host.facts()};
},{frames,count});
const trace = await simulate(900,8);
records.push({name:'warehouse-trace',...trace});