How do you push a character in a direction but stay in the navmesh like NavMeshAgent.Move()?

I am working on a RPG where the character is moved with a joystick, but I keep a navigation AI component on the actor for cutscenes. I’m in the process of trying to replace Unity’s system with yours, but I’m hitting a few snags in the porting process.

For example, when I use Unity’s Navmesh system, I call NavMeshAgent.Move(Vector3) to “push” the character in a certain direction. It can also be used for things like wind, conveyer belts, explosion knock backs, etc. By using this, I am able to always keep the actor on the Navmesh (and in the game bounds), and it will interact with other dynamic objects when moved. Is there a similar way to handle this with A* Pathfinding Pro?

Note: I am using a Recast Graph.


In the current release, this is not possible in an easy way. In the beta however it is possible.
You can take control over the movement like this

void Start () {
	ai.canMove = false;
	ai.updatePosition = false;

	// If you want to do rotation in some other way as well
	// ai.updateRotation = false;

void Update () {
	// Calculate how the AI wants to move
	ai.MovementUpdate(Time.deltaTime, true);
	var desiredVelocity = ai.desiredVelocity;

	// Where the AI wants to move during this frame
	var movementDelta = desiredVelocity * Time.deltaTime;
	movementDelta = ... // modify the movement delta however you wish
	// Actually move the AI
	ai.Move(ai.position, movementDelta);

I think you should be able to call ai.Move at any point just like Unity’s NavmeshAgent without having done all the other stuff, the only thing that might not work properly is the ai.velocity property which might return incorrect values. It is better to take full control over the movement however for performance reasons as otherwise it will have to do 2 raycasts (if you are using that for your AI) and 2 assignments to transform.position (which can be slow).
If you do test this, please share your results. This is just a beta after all.

Note however that only the RichAI movement script ensures the AI stays on the navmesh. The RichAI movement script is written specifically for navmesh-based graphs in contrast to the AIPath script which works with any graph but on the other hand knows nothing about where the boundaries of the graphs are.

1 Like