Navigating an agent + a camera

Probably one for @Cedric the nav-mesh jedi.

I’m doing something similar to this PG with click to move an agent. Crowd navigation within a navmesh | Babylon.js Playground (

The difference though is that I’m actually using this mechanism to move my camera around the scene. This works just fine with me passing the camera in as the mesh for the agent. Where stuff is starting to break, though, is when I do a click to move, but afterwards then move the camera around with its regular keyboard controls, and then I try to click to move again. Rather than start the path from where my camera currently is after the key movement, it starts it from the spot I ended on the previous click to move.

I thought I’d get around this by using the transformNode that also gets passed into the agent. I’m updating that every tick in the renderloop so that it has the position and rotation of my camera, and I see the transform node updating in babylon inspector as I move my camera around with keyboard controls, but that still doesn’t fix my issue and click to move will always start from where my last click to move ended, rather than start from where my camera is!

Any thoughts or tips about this would be appreciated.

Did you try to teleport the agent where the camera is, just before setting a new destination ?

Okay that worked haha. Thanks @Cedric :grinning:

1 Like