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?
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~
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:
Get the bounds of the target object*;
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);
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;