Search Unity

How to make agent avoid lights

Discussion in 'Navigation' started by Josh-0, Mar 14, 2019 at 4:13 PM.

  1. Josh-0

    Josh-0

    Joined:
    Oct 12, 2011
    Posts:
    24
    Hi,

    For practice, I'm trying to add behavior to the Chomper from the 3D Game Kit. So far, I've added patrol points, and re-purposed the Fleeing behavior from the Spitter to make the Chomper flee from lights.

    If the Chomper enters a trigger collider around the light, a ray is sent from the light to the Chomper checking if it is hit. If there aren't any obstacles in the way of the hit, the Chomper flees a certain distance.

    But, I would also like to add a behavior so that the Chomper doesn't go into the light. Right now, if the Chomper is patrolling, it will walk into the light and then it will flee. It would be a lot better if the Chomper would just avoid the light. Ideally, I would like to use raycasting again instead of an NavMesh Obstacles. NavMesh Obstacles would prevent the player trapping the Chomper in the light (to do damage to it). And, I would like the lights to be have the ability to be moved.

    Any suggestions would be great!

    navmesh help.jpg
     
    Last edited: Mar 14, 2019 at 4:23 PM
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    199
    Perhaps a weird idea, but you can give the lights a NavMeshAgent themselves, and set their avoidance priority really high. If you then set the agent radius to be about the same size as the light radius, you could get what you want.
     
  3. BrandStone

    BrandStone

    Joined:
    Jul 21, 2014
    Posts:
    37
    How about using navmesh areas and costs?