Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Making low priority obstacles for a Nav Agent

Discussion in 'Navigation' started by MinhocaNice, Jul 30, 2022.

  1. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    In my FPS game, the player is able to position barricades that block the path of the enemies to it. I want the enemies to first try to steer around such barricades, however if such thing is impossible they should instead treat barricades as non obstacles and brute force their way through it (there is a script that if they have a barricade in front of them they immediately attempt to destroy it).

    I was only able to make one or the other option: Either enemies always ignore barricades, meaning placing a barricade in an open area with lots of room to steer around make enemies stop in their tracks and lose their time punching it, or making so they always try to steer around them, meaning that if the player is in a completely closed house with a single barricade at the door the enemies will keep going around the house without finding the entrance, as they see the barricade as just any other indestructible obstacle.

    How do I fix that? I want to make so enemies can distinguish between low priority obstacles (ones that should preferably be steered around but if needed can be forced through) and high priority obstacles (indestructible objects where the only option is to steer around them), preferably using layers.
     
  2. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    Does anyone have any ideas on this?
     
  3. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    296
    MinhocaNice, ChrisKurhan and PutridEx like this.
  4. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    Thank you for the help. I am following this tutorial and ran into a problem, for some reason I can't reference the
    NavMeshSurface
    object in my
    NavMeshManager.cs
    script:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.AI;
    3.  
    4. public class NavMeshManager : MonoBehaviour
    5. {
    6.     public NavMeshSurface CurrentNavMesh;
    7.  
    8.     void Start()
    9.     {
    10.         CurrentNavMesh = FindObjectOfType<NavMeshSurface>();
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.        
    16.     }
    17. }
    18.  
    This is what appears, it's like the
    NavMeshSurface
    object doesn't even exist to be referenced in a script, even though I am using it just fine in my game:

    upload_2022-8-11_19-37-36.png
     
  5. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    I still didn't find a solution to this, does anyone have an idea on how to fix it?
     
  6. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    46
    So I just tried this out (put it very quickly into an existing project so forgive the few pictures to put it all together)
    So I used these

    upload_2022-11-4_20-39-42.png

    and then it all appeared fine with no errors in the inspector

    upload_2022-11-4_20-40-21.png

    I'm using the navmesh github package not the standard built in one.
    It's funny though when I just had 1 or 2 if the using .AI references it wouldn't work but with all 3 it does.
    Hope this helps.
     
    MinhocaNice likes this.
  7. MinhocaNice

    MinhocaNice

    Joined:
    May 3, 2020
    Posts:
    249
    Sorry the late reply, yes this seems to help. It appears using Unity.AI.Navigation is necessary to have the NavMeshSurface, which is odd since in the tutorial (and the code in it's github) they don't use it. Thanks.