Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Navmesh agent starts moving really slow after target reaches certain height

Discussion in 'Navigation' started by aCake0202, Apr 4, 2021.

  1. aCake0202

    aCake0202

    Joined:
    Mar 11, 2021
    Posts:
    26
    I'm not sure how to explain what's happening, after the navmesh target reaches a certain height, the agent still moves but extremely slowly.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class ZombieAI : MonoBehaviour
    7. {
    8.     private NavMeshAgent Zombie;
    9.  
    10.     public GameObject Player;
    11.  
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         Zombie = GetComponent<NavMeshAgent>();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         float distance = Vector3.Distance(transform.position, Player.transform.position);
    24.         //Run Towards Player
    25.        
    26.             Vector3 dirToPlayer = transform.position - Player.transform.position;
    27.  
    28.             Vector3 newPos = transform.position - dirToPlayer;
    29.  
    30.             Zombie.SetDestination(newPos);
    31.        
    32.  
    33.     }
    34. }
    35.  
    36.  
    Here is the code for the AI, really simple.