Search Unity

Ideas on making AIAgent avoid water?

Discussion in 'Navigation' started by Shadowing, Feb 21, 2019.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Is there a way to bake Navigation so it avoids water?
     
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    To my knowledge if water is a mesh you should be able to set it's layer in the navmesh baking. Worst case scenarios you can add mesh to the scene the occupy the same area as the water and bake those and then remove them once baked.
     
  3. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi,
    You could consider two routes for this:

    If your water is a mesh, add a collider, and add a NavMeshObstacle to it so your agents avoid it.

    or:

    If your is a plane, or something else, consider creating an empty GameObject and adding some colliders to it in the (rough) shape of your water, then adding a NavMeshObstacle to that.

    Kind Regards,

    Miggi124
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    To refine the others' answers a bit, you need to select your water plane, give it an appropriate collider, and open the navigation window. There, navigate to the object tab and you'll see the possibility to set an area type. Simply set your water to a non-walkable surface and you're good to go. No need for NavmeshObstacle components and such.