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.
  2. Dismiss Notice

[RELEASED] Enemy AI

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

  1. sebasfreelance

    sebasfreelance

    Joined:
    Aug 27, 2015
    Posts:
    240
    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:
    52
    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:
    240
    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:
    240
    solved, the helicopter was not baking in the navigation, ;)
     
    BroVodo and Viniterra like this.
  5. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    189
    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:
    189
    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:
    189
    Sorry, I've missed this mesage. I'll try to finish this tutorial at the beginning of the year.
     
  10. jglavas

    jglavas

    Joined:
    Oct 31, 2021
    Posts:
    3
    I just got the asset myself and followed the tutorial
    from the dev but I couldn't get Kyle to shoot at me, he does aim but not shoot... Yes i have both tag and layer set to "Player"... Basically i know the player isnt a problem because the prefabs that come with the asset work and shoot the player without a problem but my assets only aim.. Any help? Thanks!
     
  11. jglavas

    jglavas

    Joined:
    Oct 31, 2021
    Posts:
    3
    Update: I found that my AI only shoots the player when I get extremely close and it also shoots 1 or 2 bullets while the prefabs that come with the asset shoot my player without a problem. Problem is then not the player but my AI. I also copied all the components and layers from prefab version of AI to mine and still no hope...
     
  12. mario_code4ever

    mario_code4ever

    Joined:
    Jan 9, 2020
    Posts:
    36
    need help I did all as the video instructed. But my enemy is aiming at the ground. He does animation and detects me but he is aiming at me at the ground. Please help
     
  13. jglavas

    jglavas

    Joined:
    Oct 31, 2021
    Posts:
    3
    Have you tried setting the Aim Offset in the RifleStats ScriptableObject? Editing this while in play mode should help you fix the animation.
     
  14. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    189
    Hello, for a faster response, sumbit you issue in the Support for the Enemy AI package form.

    Are there any error messages in the Console?
     
  15. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    189
    Hello, for a faster response, sumbit you issue in the Support for the Enemy AI package form.

    You can check the offsets, as jglavas mentioned, and also the Aim Target transform. Maybe it is set at the root of the player, hence the enemies aiming down.

    The target must be at the chest of the player, or at some desirable position you want them to aim.
     
  16. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    189
    New Tutorial Video: Mastering Enemy AI: Building Custom FSMs for NPCs

    Hello everyone,

    We've just released a new video tutorial on creating custom Finite State Machines (FSMs) for hostage NPCs using our Enemy AI system. If you're interested in enhancing your game's AI, this video might be helpful.

    What You'll Learn:

    • Building a custom FSM for a hostage NPC
    • Creating states and transitions
    • Implementing actions to enhance your game's AI
    • Practical examples and demonstrations

    Watch the Video:

    Mastering Enemy AI: Building Custom FSMs for NPCs



    Feel free to watch and share your thoughts or questions in the comments.

    Happy learning!
     
    Last edited: Sep 28, 2023
  17. ShinigamiYato

    ShinigamiYato

    Joined:
    Nov 29, 2022
    Posts:
    1
    hello hi i really love this asset but need help implementing colliders as I want to use bullets instead of ray casts to do damage to enemies. i think many people will be interested if you make a youtube video showing how to take damage using colliders. or can you pls reply to this email showing me how i can implement it. once again i really love this asset its just that I'm a little stupid and cant figure it out
     
  18. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    189
    Hi, thanks for the feedback, and for the suggestion.

    As for changing the system to use bullets, these are the basic steps:
    1. Create a bullet prefab with a collider and a script to handle bullet behavior.
    2. Modify the shooting mechanic to instantiate the bullet prefab when shooting, instead of the raycast.
    3. In the bullet script, detect collisions with enemies using OnTriggerEnter() or OnCollisionEnter().
    4. When a collision occurs, apply damage to the enemy using the enemy's health system.
    Indeed, this is a great idea for a video tutorial. I'm considering creating one to demonstrate this feature. Thanks again!