# Optional callback parameter in RecastJSPlugin?

**URL:** <https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078>\
**Category:** Questions\
**Created:** [April 17, 2021, 6:57am UTC](https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078 "2021-04-17T06:57:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![slin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/slin/32/36084_2.png) [@slin](https://forum.babylonjs.com/u/slin)\
**Post date:** [April 17, 2021, 6:57am UTC](https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078/1 "2021-04-17T06:57:48Z")

</div>

Hello,

I have a request for NavMesh hopefully it is right to at @Cedric.

My wish:  
I would like to have a callback function I can pass into the constructor of [RecastJSPlugin](https://github.com/BabylonJS/Babylon.js/blob/34802bcae6c23cc4a452a31101305f0bc051bf76/src/Navigation/Plugins/recastJSPlugin.ts). When this callback function is present, the update() function in RecastJSPlugin would pass the new positions to the calllback function, instead of directly updating the positions of transform nodes. To avoid disrupting the existing api, this callback can be optional and when it is omitted, direct position update to the transform nodes is applied.

Why I want to have this api:

I use babylon.js with react and follows the flux pattern. Basically, actions such as user inputs trigger changes to a central state; the central state notifies the react app to update and notifies changes in babylon scene. For example if I want to move a mesh, mouse click on a target destination is the action. I keep the position of the mesh in the central state. I would like to implement the update of position to the central state in the callback function I wish to have. And when the central state is updated, it will notify the observer to update the transform node position on the 3D scene as side effect.

I think this pattern helps to separate the app code logic from rendering. For example, if I have modules for save the position of the mesh, or if I have another logic that need to take the mesh position into consideration, these modules only need to access the central store. They don’t need to read directly from the mesh.

---

<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:** [April 17, 2021, 10:44am UTC](https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078/2 "2021-04-17T10:44:44Z")

</div>

Let me check how to do that 🙂

---

<div class="post-metadata">

**Author:** ![slin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/slin/32/36084_2.png) [@slin](https://forum.babylonjs.com/u/slin)\
**Post date:** [April 17, 2021, 4:23pm UTC](https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078/3 "2021-04-17T16:23:24Z")

</div>

Hi @Cedric,

Thanks. I actually notice another requirement I need. I checked the rotation example.  
[https://playground.babylonjs.com/#6AE0RP](https://playground.babylonjs.com/#6AE0RP)

The rotation seems to happen at the same time the box is moving. I was thinking to rotate my unit to face the direction of the next travel step first before moving. Do you think this is possible to support this?

If not, I am thinking my original wish (adding the callback function) is not enough to achieve this kind of rotation behavior. Shall I just use computePath() and then do the update over time myself instead?

---

<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:** [April 19, 2021, 9:28am UTC](https://forum.babylonjs.com/t/optional-callback-parameter-in-recastjsplugin/20078/4 "2021-04-19T09:28:03Z")

</div>

No, it’s not ☹  
Recast doesn’t support agent orientation. Only position + velocity. Orientation is computed as the direction of movement, nothing more.  
To uncorrelate agent position from your representation, you can make your character to try to follow the agent. With no parenting between your character and the agent. Agent becomes an hint to follow.
