Search Unity

NavMesh on Terrain object breaking script for an NPC to follow the player

Discussion in 'Navigation' started by jcmyers2k, Mar 26, 2022.

  1. jcmyers2k

    jcmyers2k

    Joined:
    Jan 20, 2022
    Posts:
    4
    I'm currently working on a basic 3d RPG game. I've made a basic script where the other party members follows the main one that the player controls in the overworld. It utilizes NavMesh and tested it on a plain 3d object, and it worked perfectly fine. I then tried to use it on a Terrain object so I can edit the play area through that, however baking the scene with the terrain object breaks the script for an unkown reason, and the other party members go to the center of the scene and stay there without following the player. The script in question goes as such...

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class pmWorldMove : MonoBehaviour
    7. {
    8.  
    9.     //"Party Member" World Move
    10.     public Transform player;
    11.     NavMeshAgent agent;
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         agent = GetComponent<NavMeshAgent>();
    18.  
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void FixedUpdate()
    23.     {
    24.         agent.destination = player.position;
    25.     }
    26. }
    any idea why it would break?