Closest point between Seeker and Target

Hi,

I’m using a Grid Graph on my game and currently when I start a Path it will always have the same end point, which is either the target’s position or the closest walkable node to that point, depending on the settings I put on the start-end modifier. This causes the agents to agglomerate in a point, usually making them travel a lot without needing to.

What I want is for the agent to calculate the path that has the end point on a walkable node that is close to the target but has the lowest cost (travel distance). How can I do it in the Free version?

Thanks in advance

Set the Start/end Modifier to the exact point, and run a Is point reachable test

Here is mine that you can just paste in~

`
public bool CheckIfPathIsPossible(Vector3 PathStart, Vector3 PathEnd){

	Pathfinding.Node node1 = AstarPath.active.GetNearest(PathStart, NNConstraint.Default).node;
	Pathfinding.Node node2 = AstarPath.active.GetNearest(PathEnd, NNConstraint.Default).node;
	
	if (!Pathfinding.PathUtilities.IsPathPossible (node1,node2)) {	
		
		return(false);
	}
	else{
		
		return(true);
	}
}`

If it is false you get the nearest walkable node |or| move the target to the edge of whatever collider its touching |or| Change your distance needed to end the path to the distance from there nearest node |or| On collision enter, have the distance needed to end the path increase based on the colliders size… Or anything along those lines~

Also look at this thread for some info on nearest walkable node
http://arongranberg.com/vanillaforums/discussion/686/get-nearest-node#latest

Thanks for the reply!

I actually managed to solve it using a different strategy. Since my objects have bounds (AABB to be more precise), I’m doing the following:

  1. Get the bounds of the target object*;
  2. Clamp the x y and z values of the Agent’s position to the bounding box values (we will obtain the point in the box that is closer to the Agent);
  3. Call Seeker.StartPath using the obtained clamped value as the target.

This way the calculated path will end in the intended node.

*In case you need to calculate an object’s bounds (assuming the object has a mesh) this is what you do:

Bounds bounds = new Bounds(); Renderer[] renderers = gameObject.GetComponentsInChildren<Renderer>(); // Get all renderers inside the GameObject foreach (Renderer renderer in renderers) { if (bounds.size == Vector3.zero) // Initialize bounds bounds = renderer.bounds; else bounds.Encapsulate(renderer.bounds); // Modify the bounds variable to include each renderer's bounds } return bounds;