How do I apply force for movement when using the NavmeshAgent for navigation?

Hi,

I have enemy spheres that I want to roll towards the player using the path that is generated by the nav mesh.

When I use the navmesh.SetDestination, the spheres just slide towards the player (pathfinding works here).

In the update function; If I set the destination, stop the navmesh, and then apply force in the direction of the navmesh’s next position. The ball just seems to roll towards the players location (without pathfinding).

Is it possible to use the nav mesh in this way? I only want to use it for the pathfinding element, and movement will be handled by physics.

Thanks in advance

Alright so after a bit of playing around I got this to work using the CalculatePath, NavMeshPath and the corners array.

Position 0 in the array appears to be the position of the object itself. Originally I just set the direction to position 1 which is like the next waypoint, but the spheres were getting stuck on the corners of the navmesh when the distance between position 0 and 1 was too small. The loop will look for a decent sized distance before trying to move there.

Not the most elegant solution but, given my limited knowledge, it’s all I could come up with. Hopefully this helps someone!

	Transform player;
	NavMeshAgent nav;
	NavMeshPath navPath;
	Vector3 direction;
	
	void Awake ()
	{
		player = GameObject.FindGameObjectWithTag ("Player").transform;
		nav = GetComponent <NavMeshAgent> ();
		nav.Stop (true);
		navPath = new NavMeshPath ();
	}

	void Update ()
	{
            nav.CalculatePath (player.position, navPath);
		int i = 1;
		while (i < navPath.corners.Length) {
			if (Vector3.Distance (transform.position, navPath.corners *) > 0.5f) {*

_ direction = navPath.corners - transform.position;_
* break;*
* }*
* i++;*
* }*
* }*

* void FixedUpdate()*
* {*
_ rigidbody.AddForce (direction.normalized * moveSpeed * Time.deltaTime);_
* }*