Stop NavMeshAgent ~1.5 units from target

How can I get my NavMeshAgent to stop about 1.5 units from the selected target? I am trying to create a 3rd person camera, and I am trying to get these actions to work with NavMeshAgent for easier controlling for users (game requires little to no accuracy). Currently, the only thing that can be interacted with is a chunk of “gems” with the “Gem” script on them. I have my player stop “1.5f” units from the “Gem”. But then the part after it checks distance from “Gem” to make sure it is close enough to activate the collection of it (to stop it from activating it as soon as it is clicked, so that other players/NPC may have a chance at it too). Currently, it stops about 1.5 units it looks like, but it is never 1.5 FROM the direction the player is coming from (so it may over shoot it and walk over it). But even when that happens, the check for distance does not go off, leaving the gem uncollected for several dozen clicks (even through the distance appears to be less than 2 units).

using UnityEngine;
using System.Collections;

public class MouseControlledPlayer : MonoBehaviour {

    public NavMeshAgent body;
    public Camera cam;

    void Start () {
        body = gameObject.GetComponent<NavMeshAgent>();
    }
   

    void Update () {
        RaycastHit hit;
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.GetComponent<Gem>())
                {
                    print("Found Gem!");
                    body.SetDestination(hit.point - (transform.forward * 1.5f));
                    if (Vector3.Distance(hit.point, transform.position) <= 2)
                    {
                        hit.transform.GetComponent<Gem>().taken = true;
                    }
                }
                else
                {
                    body.SetDestination(hit.point);
                }
            }
        }
    }
}

Your distance check in line 25 only happens when the mouse is down AND you are hovering over the gem. You should probably save the gem you are moving towards, or its position, and then check that outside of your if(Input) block.

Wow, thank you. I feel like an idiot for not realizing that. I basically made my own (currently) simple state machine so that the item hit and the new location are correctly used for their intended needs. Although I do have a problem with getting numbers below 1.2f for a distance between me and the NavMeshAgent.SetDestination(), but that could be a problem with my capsule character (I don’t know).