3

Is there a way to code in NavMeshAgent to work in 'air' inside Unity such that an enemy AI can follow the character up and down without the need to create a floor or multiple floors? My code only works for 3D on 'ground' characters and not on 'flying' ones.

public LayerMask aggroLayerMask;

private Collider[] withinAggroColliders;
public Player player;
private NavMeshAgent navAgent;

void Start()
{
    navAgent = GetComponent<NavMeshAgent>();
}

private void FixedUpdate()
{
    withinAggroColliders = Physics.OverlapSphere(transform.position, 450, aggroLayerMask);
    if (withinAggroColliders.Length > 0)
    {
        ChasePlayer(withinAggroColliders[0].GetComponent<Player>());
    }
}

void ChasePlayer(Player player)
{
    this.player = player;
    navAgent.SetDestination(player.transform.position);
}

}

0 Answers0