Moving object to the exact position

Hi.

I’m trying to create some sort of turn-based strategy game and decided to use A* project with this script as the base for my AI tests:

`using UnityEngine;
using System.Collections;
//Note this line, if it is left out, the script won't know that the class 'Path' exists and it will throw compiler errors
//This line should always be present at the top of scripts which use pathfinding
using Pathfinding;
public class AstarAI : MonoBehaviour {
    //The point to move to
    public Vector3 targetPosition;
    
    private Seeker seeker;
    private CharacterController controller;
 
    //The calculated path
    public Path path;
    
    //The AI's speed per second
    public float speed = 100;
    
    //The max distance from the AI to a waypoint for it to continue to the next waypoint
    public float nextWaypointDistance = 3;
 
    //The waypoint we are currently moving towards
    private int currentWaypoint = 0;
 
    public void Start () {
        seeker = GetComponent<Seeker>();
        controller = GetComponent<CharacterController>();
        
        //Start a new path to the targetPosition, return the result to the OnPathComplete function
        seeker.StartPath (transform.position,targetPosition, OnPathComplete);
    }
    
    public void OnPathComplete (Path p) {
        Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
        if (!p.error) {
            path = p;
            //Reset the waypoint counter
            currentWaypoint = 0;
        }
    }
 
    public void FixedUpdate () {
        if (path == null) {
            //We have no path to move after yet
            return;
        }
        
        if (currentWaypoint >= path.vectorPath.Count) {
            Debug.Log ("End Of Path Reached");
            return;
        }
        
        //Direction to the next waypoint
        Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
        dir *= speed * Time.fixedDeltaTime;
        controller.SimpleMove (dir);
        
        //Check if we are close enough to the next waypoint
        //If we are, proceed to follow the next waypoint
        if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) {
            currentWaypoint++;
            return;
        }
    }
}`

I found out one problem: what I really want to do, is to move character to exact position of my double right mouse button click. The point is I can’t because of this “if” statement:

if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) { currentWaypoint++; return; }

I tried to change the nextWaypointDistance value to the absolute minimum (as close to zero as it’s possible) but the result is that objects movement is not correct due to too low value of this variable.

So the question is: how can I move object to specified target without stopping it before the destination?
Thanks for any advice.

You need to simply change your Seeker.ExactEndPoint to SnapToNode. Alternatively, you could skip the last node and use the grid center.

Thank you very much for your answer but it doesn’t seem to be perfect solution. Now I have smaller problem: my character stops as the object “collide” with the target:

As you see the point on the grid where I clicked is not the center of the objects base. Any advice? Pivot of the object is set exactly in the center of the object.

Your code control how near of the last point it will be. Probably you are considering it done with a distance greater than object radius.