Search Unity

How to make agent avoid lights

Discussion in 'Navigation' started by Josh-0, Mar 14, 2019.

  1. Josh-0

    Josh-0

    Joined:
    Oct 12, 2011
    Posts:
    26
    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
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    382
    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:
    65
    How about using navmesh areas and costs?
     
  4. Josh-0

    Josh-0

    Joined:
    Oct 12, 2011
    Posts:
    26
    The obstacle avoidance is good for the most part. But, if you take the light with the obstacle and move it towards the agent, you can "push" the agent backwards. I want the creature to avoid the light, but if the light moves towards it, then it might go into the light a little bit and take damage. I wish I knew how the agent is recalculating the path to avoid the obstacle, because then I could probably make something a little more custom.

    As far as navmesh areas, as far as I can tell, that needs to be baked. The lights move, so is there a way to have moveable areas?
     
  5. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    382
    Read attentively, I said giving the light a NavMeshAgent and set their avoidance priority high. That way other agents should step out of the way of the light, as long as their priority is lower (I believe the range is 0 to 100).
     
  6. Josh-0

    Josh-0

    Joined:
    Oct 12, 2011
    Posts:
    26
    Sorry, I tried it both ways. The way you suggested pretty much works exactly the same way as the obstacle method (Unless I'm doing something wrong). And, it does work to some degree, just not in the way I'm looking for. I want there to be some overlap, and with that method the avoidance is too perfect. But, maybe for now it's the best solution. Thanks.