How to make the agent reach the nearest "area of an object"

Hi everyone
I’m new to this world and i cant figure out how I can make an AI not reach the center of the object I selected on the script but his area.
In particular my AIs should get the bottom of the screen with the shortest way (not the center of the bottom screen). With transform i can use 3 coordinates (a point), i need the AIs go to a line, not to a point.
This is my simple script:

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

public class Enemy : MonoBehaviour
    public Transform Player;
    NavMeshAgent agent;

    // Start is called before the first frame update
    void Start()
        agent = GetComponent<NavMeshAgent>();

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


Thanks for your time


Ok I see now your problem :smiley:

Well, I don’t know if there is some function to calculate the shortest way to any point of a given mesh. IF it exists, is what you want.

But, I always try to solve the problems with creativity. In this case, i would make the Arrival zone, have multiple empty object chiilds called for example “Destination1”, “destination 2”…, in all the lenght of the Arrival zone.

Then, You need to calculate each frame in Update (or every second or something like this with a corutine) what is the closest Destination to the moving object, using the function Vector3.Distance(). This way, it will move to the closest destination from its actual position.

As more Destinations childs in arrival zone, more accurate the path.


Hi @tormentoarmagedoom and thanks for Your time!
I thought about this method too but I thought It was too heavy for the game. The script does not seem so simple, im a noob :cry: