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.

[RELEASED] Enemy AI

Discussion in 'Assets and Asset Store' started by Viniterra, Mar 24, 2020.

  1. sebasfreelance

    sebasfreelance

    Joined:
    Aug 27, 2015
    Posts:
    234
    Hi,

    I need help, for some reason, the enemy crosses the obstacles, I have in EnemyStats in Obstacle Mask the "obstacle" layer and the helicopter in the same layer.

    but when the enemy goes from wp2 to wp3, he goes through the helicopter, he doesn't go around from wp2 to wp3.

    that could be happening?
     

    Attached Files:

  2. BroVodo

    BroVodo

    Joined:
    Oct 2, 2012
    Posts:
    49
    Does the helicopter have a collider attached? Maybe it needs one, depending on how the AI works.
    Or (more likely) it needs a navmesh obstacle component:
    https://docs.unity3d.com/2020.3/Documentation/Manual/class-NavMeshObstacle.html


    Are you setting the target for the NPCs when you spawn them? Do the NPCs require waypoints, and are you setting the waypoints on the NPCs when you spawn them?

    If you are spawning the player as well, you need to make sure you spawn the player before you make some part of it a target.


    Unrelated -
    There seems to be some errors occurring when setting layers and tags. Appears to be caused by the first skinned mesh not being attached to the root bone. Other skinned meshes are ignored and may need to have layers set manually.
     
    Last edited: May 20, 2022
    Viniterra likes this.
  3. sebasfreelance

    sebasfreelance

    Joined:
    Aug 27, 2015
    Posts:
    234
    Hi,

    yes, it has a box collider, I also tried with the NavMeshObstacle, but when I have this added, when the enemy approaches, it starts to do a strange behavior when walking, it does not take the steps correctly.

    As you can see in the video, I turn the NavMeshObstacle on and off, the first time it works weird, when I turn the NavMeshObstacle on and off it seems to work fine.
     

    Attached Files:

  4. sebasfreelance

    sebasfreelance

    Joined:
    Aug 27, 2015
    Posts:
    234
    solved, the helicopter was not baking in the navigation, ;)
     
    BroVodo and Viniterra like this.
  5. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    176
    BroVodo likes this.
  6. dgoodman-icf

    dgoodman-icf

    Joined:
    Jan 7, 2019
    Posts:
    36
    How can I make the agent run for cover if the player is within x meters? They stop shooting if you teleport to within 1-2 meters but they're still in the Attack Action/RemainInState.
     
  7. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    176
    The default behaviour in the enemy FSM is to go into direct engagement with the player when he is within the near radius (near decision). You can replace that in the FSM with a custom state/action that performs the desired behavior.
     
  8. dotomomo

    dotomomo

    Joined:
    Apr 13, 2020
    Posts:
    1
    Hello.

    Any plans on releasing the video which details expanding the FSM?

    I want to create an 'electrocuted' state which triggers an animation and prevents the enemy from shooting, and think a custom state would be the best way to achieve this, but not entirely sure.

    Thanks!
     
    Holydh likes this.
  9. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    176
    Sorry, I've missed this mesage. I'll try to finish this tutorial at the beginning of the year.