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

Get obstacle that makes path destination unreachable

Discussion in 'Navigation' started by JannickL, Mar 3, 2018.

  1. JannickL

    JannickL

    Joined:
    May 18, 2016
    Posts:
    78
    Hi there,
    i ran into a problem with my agents. It's a defense game and the player is able to build walls (navmesh obstacles).

    When the player i.e builds walls arround the entire object so that there is no way inside the agents can't walk the path to the destination (because the path is invalid for sure).

    I want the agents to walk as near as possible and attack the walls to get to the target destination.

    However, as soon as I start the game and the agents notice that they can't reach the target destination because it's blocked → they don't start moving.

    How can I actually get the (closest) obstacle that blocks the path? Because when I get the obstacle I can set the destination to the obstacle transform and let the ai attack the wall.

    Stuck with this in weeks...

    Any help is appreciated.

    Greets! :)
     
  2. GWLPXL

    GWLPXL

    Joined:
    Jun 24, 2017
    Posts:
    52
    The simplest solution is to make a 'path' area that the player can't build on, so they can never completely block the AI.

    Alternatively, you program in something when a path isn't found. Perhaps a generic move and check what's in front script?

    Alternatively, you can program in a set of destinations instead of just the final one.

    Alternatively, you can avoid using the Navmesh and just program walk in a straight line and then do stuff when bumping into walls (either attack or turn).

    What's the point of the game? Is this a tower defense? Is it a mob defense? Is it even a defense?