Navmesh agent is falling close to the floor/surface is there a way to keep the agent height ?

My agent is a drone that is already floating in the air and should float in the air. but after adding the navemsh agent component to it when running the game the droid is falling close to the floor/surface and never keep his original height.

This is a screenshot of the drone inspector settings start position height on Y is 51.71

And this is a screenshot of the drone after running the game after he is falling/getting closer to the floor/surface:
Now the height position on Y is 50.083

I opened the navigation window : in the agents tab tried to change the height from 2 to 7 or more but it didn’t work so I tried in the bake tab tried to change the agent height the step height the drop height but nothing helped he keep getting closer to the floor/surface.

This is the script I’m using with the drone to move the drone between waypoints.
The script is working fine but the drone height is too low. I want to be able to control the drone height :

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;

public class Waypoints : MonoBehaviour
{
    public List<Transform> points = new List<Transform>();
    public List<GameObject> npcs;
    public NavMeshAgent agent;

    private int destPoint = 0;
    private int damping = 2;

    void Start()
    {
        var wayPoints = GameObject.FindGameObjectsWithTag("Waypoint");
        foreach (GameObject waypoint in wayPoints)
        {
            points.Add(waypoint.transform);
        }

        npcs = GameObject.FindGameObjectsWithTag("Npc").ToList();

        // Disabling auto-braking allows for continuous movement
        // between points (ie, the agent doesn't slow down as it
        // approaches a destination point).
        agent.autoBraking = false;

        GotoNextPoint();
    }


    void GotoNextPoint()
    {
        // Returns if no points have been set up
        if (points.Count == 0)
            return;

        // Set the agent to go to the currently selected destination.
        agent.destination = points[destPoint].position;

        // Choose the next point in the array as the destination,
        // cycling to the start if necessary.
        destPoint = (destPoint + 1) % points.Count;
    }

    void VisitNpcs()
    {
        var npc = npcs[Random.Range(0, npcs.Count)];
        var distance = Vector3.Distance(npc.transform.position, agent.transform.position);

        if (distance > 7)
        {
            agent.destination = npc.transform.position;
            var collider = agent.GetComponent<BoxCollider>();
            if (collider != null)
            {
                collider.enabled = false;
            }
        }

        if (distance < 2)
        {
            agent.isStopped = true;

            Vector3 lookPos = agent.transform.position - npc.transform.position;
            lookPos.y = 0;
            var rotation = Quaternion.LookRotation(lookPos);
            npc.transform.rotation = Quaternion.Slerp(npc.transform.rotation, rotation, Time.deltaTime * damping);
        }
    }

    void Update()
    {
        // Choose the next destination point when the agent gets
        // close to the current one.

        if (!agent.pathPending && agent.remainingDistance < 0.5f)
        {
            GotoNextPoint();
        }

        VisitNpcs();
    }
}

I want to keep the drone in his original height.

Hi,

Change NavMeshAgent base offset

3 Likes

Thank you.

Working. I changed it before asking here but it didn’t work.but now I changed it much more I moved the base offset much more down almost to ground level and now it’s working. Maybe the mesh pivot position on my droid is wrong ?

Anyway the solution is like you wrote changing the base offset.

This is working for me :