onReachTargetObservable and Non-Parent Agent

Greets all,

I am unsure what the best approach for my project is. Currently the whole project expects my Entity to have a root (root of glb), because all my calculations are done by entity.root.position and .rotationQuaternion. Which is why I wouldn’t like to change anything here (even tho it might be possible to use absolute values), because i.e. buildings have no crowd/agent. Now for RecastJS I have to set parent, if not I get an issue with onReachTargetObservable, that sets “active command”-flag to false (so agents iteration can be skipped). It triggers before the mesh (root) reaches its target/destination position and at next agentGoto the mesh jumps because first getAgentPosition is not equal to my mesh position. Any other idea than to set agent transform as new root? I also tried moveAlong onReachTargetObservable, but here it jumps again. Seems like using absolute values would be the best, but feels unneccesary for obstacles, buildings etc. Are there any other disadvantage of absolute values than not being accessible before scene&mesh is ready (fyi: I do use instantiateModelsToScene)?

Here my PG to illustrate it:

cc @Cedric

Yes, because of avoidance, the event is triggered when the agent is within a radius of the destination.
Value is accessible, per agent RecastJSCrowd | Babylon.js Documentation

So, when the agent will not be exactly at the intended position. Think of 2 agents that are given the same position. Without a radius check, none of them would ever reach the destination.


I think the solution will be if crowd.getAgentVelocity(…).length() is zero.

It sounds a bit weak to me. Because agent can be stuck behind a bunch of other agents…or obstacles…

1 Like

Do you have any good idea for RTS scenario?

My current approach, which seems to work, is to handle each command (attack, gather, follow, craft, patrol, skill…) in onReachTargetObservable and then teleport agent transform node to entity (mesh) position. Cannot find the corresponding PG, but I can share my full project’s code parts by private messages.