# Stop character from moving after reach his destination?

my script is for character moving to the certain point on the terrain. To get this point I have to use mouse. When I click on the terrain, my character goes there. Now, If he reach his point and something like enemy come to push him, he moves away from his point !!? What I want is to make him stop there and no power in the world could move him.

private NavMeshAgent mAgent;
public Vector3 point_;
public float mark;
public bool actives;

void Start()    {
mAgent = GetComponent<NavMeshAgent>();

}

// Update is called once per frame
void Update()    {
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit mousePoint;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(mouseRay, out mousePoint, 100))
{
point_ = mousePoint.point;
mAgent.SetDestination(mousePoint.point);
mark = Vector3.Distance(point_, gameObject.transform.position);
}

}

}


You can use a constrain on the rigidbody https://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html

Or if the external force is a physic-related one make it cinematic. https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

The second one is faster to implement (a click in your rigidbody) so you can test it faster. You can also change it so its kinematic when stoppped and not kinematic when moving via script.

Could you just set isKinematic on the RigidBody to false once he reaches the destination? This would prevent the rigidbody from being effected by physics, which is kind of like preventing any force in the world from moving it :).

• Zachary, I wish you were right but still he got pushing from enemies !! Image kinematic is true or false is the same. Is it because enemy have also navmeshAgent ?. Adria , Both methods doesn't work and I don't know why !!
– Omer
Jun 9 '18 at 8:11
• Well if it really is the unity physics making it move then disabling the rigidbody should do the trick. If it still moves even after unity physics are turned off then I would say some other component is making it do that. Without seeing any code or behaviour this is a little hard to identify Jun 10 '18 at 4:04
• What happens if you turn off (set the enabled variable to false) the collider on that object either while it is moving or when it reaches your destination? Jun 13 '18 at 15:37
• I don't thing it's from the things you mentioned. I solved this issue by increasing "Stopping Distance" from 0 to 1 for enemy navmeshAgent. Thank you Zachary.
– Omer
Jun 13 '18 at 22:40