Basic AI problem [Help]

Hello

So i have made some very basic AI code, the problem I am getting and can’t fix is that I want it to stop when it gets to the minDist. But for some reason even if I set the moveSpeed to 0 or even take out moveSpeed completely. The AI still moves? I’m soo confused!?

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BasicAI : MonoBehaviour {

    public Transform myTransform;
    public Transform myTarget;
    Renderer myRender;

    public float moveSpeed;
    public float minDist;
    //public float maxDist = 10.0f;

    // Use this for initialization
    void Start ()
    {
        myRender = GetComponent<Renderer>();
        myRender.material.color = Color.white;
    }
   
    // Update is called once per frame
    void Update ()
    {
        transform.LookAt(myTarget);
        if (Vector3.Distance(myTransform.position, myTarget.position) > minDist)
        {
            //Chase
            moveSpeed = 3.0f;
            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
            myRender.material.color = Color.red;
        }
        if(Vector3.Distance(myTransform.position, myTarget.position) <= minDist)
        {
            moveSpeed = 0.0f;
            myRender.material.color = Color.white;
        }
    }
}

Nevermind, after commenting out some lines I came to the conclusion that the rigidbody component was screwing around with the object. So i had to freeze the rotations of the X and Z of the cube and it works perfectly. Thank you.

Vector3.MoveTowards will move your ai to the position without over shooting it if its going to fast.

Thank you!!