drone follow and keep distance

Hello

I am trying to have object follow another objectg but keep a certain distance and it should stay above ground as it is a drone thats follows a player.

Right now it just comes all the way into the player and keeps pushing him.
It also penetrates the ground, while i want him to stay above ground

public class followPlayerDrone : MonoBehaviour
{


    public Transform Player;
    public float speed;
    public RangeSensor sensor;

    public Vector3 offset;
 


    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {

        var detected = sensor.GetNearest();
        if(detected !=null)
        {
            followPlayer();

        }

    }


    public void followPlayer()
    {
        transform.LookAt(Player.transform);
        transform.position += transform.forward  * speed * Time.deltaTime;

       /* if((transform.position - Player.transform.position).magnitude < 2f)
        {

            transform.position = this.transform.position;
        }*/
      


    }

    public void moveTowards()
    {
        transform.position = Vector3.MoveTowards(transform.position, Player.position, 250 * Time.deltaTime);
      

    }
}

To keep the same height you can change
transform.LookAt(Player.transform);
into
transform.LookAt(new Vector3(Player.transform.position.x, transform.position.y, Player.transform.position.z);

this will make it look at th Player’s X Z but will keep your drone’s Y.

I see you have a public Vector3 offset, I guess you set it in the inspector.
You could make a simple check like this in your FollowPlayer

if (transform.position - Player.transform.position > offset)
{
    transform.LookAt(...)
    transform.position += ...
}

Not optimised at all but should be functional, (didn’t check the order for the transform position comparison, might be the other way around…)