Optional callback parameter in RecastJSPlugin?

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. 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.

Let me check how to do that :slight_smile:

2 Likes

Hi @Cedric,

Thanks. I actually notice another requirement I need. I checked the rotation example.
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?

No, it’s not :frowning:
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.

1 Like