Enemy AI floats when chasing me

Hello, so i am a bit new to Unity and i have just hit this major problem. When the Enemy AI begins to chase me, it starts floating in the air. It should not be doing this but it is. I’ve seen many comments saying that the way to fix this is to adjust the y position, but i don´t know how to write that in my script. Can someone please help. Thanks in advance.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AIController : MonoBehaviour
{

public Transform Player;            //Reference to the player
int MoveSpeed = 5;                  //AI speed
int MaxDist = 2;                    //Action at a dsitance
int MinDist = 2;                    //When enemy stops
int MehDist = 5;                    //Sixth Sense ring
int MoveDist = 15;
private Animator animator;

void Start()
{
    animator = GetComponent<Animator>();
}

 
void Update()                                                                  //This will tell the AI what to do 
{
    transform.LookAt(Player);                                                  //Looks at the player

    if (Vector3.Distance(transform.position, Player.position) <= MoveDist)      // Moves towards the player
    {
        animator.SetBool("isIdle", false);
        transform.position += transform.forward * MoveSpeed * Time.deltaTime;

        if (Vector3.Distance(transform.position, Player.position) <= MaxDist)  //If enemy gets close
        {
            GameOver();                                                        //Plays GameOver screen
        }

        if (Vector3.Distance(transform.position, Player.position) <= MehDist)  //if enemy is inside the ring
        {
            Sensor();                                                          //Calls sensor function
            animator.SetBool("isAttacking", true);
        }

        else if (Vector3.Distance(transform.position, Player.position) >= MehDist) //If enemy is away from the ring
        {
            FindObjectOfType<AlertRing>().Clear();                                 //The ring turns yellow
            animator.SetBool("isAttacking", false);
        }

    }
}

void Sensor()                                                                  //ALERTS THE PLAYER
{
    FindObjectOfType<AlertRing>().Sense();
}

void GameOver()
{
    FindObjectOfType<GameOver>().EndGame();
}

}

You are using

transform.position += transform.forward * MoveSpeed * Time.deltaTime;

to move him so probably his face is facing UP al little before he gets level with your character because of the “lookat” and he leviates.


Vector3 tmpPos = transform.position;
tmpPos.y = 0;
transform.position = tmpPos;

something like this.