Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    193
    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:
    193
    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:
    2
    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:
    193
    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:
    193
    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:
    193
    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:
    193
    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:
    193
    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!
     
  19. haroonyousaf

    haroonyousaf

    Joined:
    Apr 9, 2017
    Posts:
    4
  20. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    193
    Hi, thank you for your interest. The visual navigation of the NPCs is achieved through the animation system (movements) and transform rotations in some cases.

    The NavMesh Agent is employed for pathfinding (setting goals), obstacle avoidance, goal reaching, etc.

    Since the mentioned solution is proprietary, unfortunately, I do not have access to it.

    However, I believe that as long as it provides the same fields/methods as Unity's default pathfinding solution, you may be able to adjust the code lines to make it work properly.

    The fields used by the NavMesh Agent include velocity, desiredVelocity, speed, destination, remainingDistance, stoppingDistance, pathPending, and radius.

    References to the NavMesh Agent can be found in the state controller and in the enemy animation scripts.
     
  21. Sungbean23

    Sungbean23

    Joined:
    Dec 27, 2021
    Posts:
    1
    But I have a question wouldn't this overwrite all existing tags and layers?
     
  22. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    193
    Sorry, I didn't understand your question. What is the context?
     
  23. rc82

    rc82

    Joined:
    Jan 28, 2020
    Posts:
    44
    Hey if you haven't figured it out ping me. Basically you go to the attack action, and go to the shoot method. Where it goes to cast a shot, you just instantiate the projectile instead. Then you need to do on trigger collisions to get the health class do apply damage.

    You'll need to set up an object Pooler, ideally update the weapon class stats with projectile speed, etc, beforehand as you'll need to be able to get that info on an impact, then a projectile script to do logic on hit, and I have jobified it for the raycasting, but you can just do it in the projectile script.

    I'll add a video later. It's also pretty easy to keeot both projectile and hitscan type of weapons.
     
    Last edited: Jan 9, 2024
    Viniterra likes this.
  24. wechat_os_Qy01kp4Sf_0wUlTdZmZpHjg7k

    wechat_os_Qy01kp4Sf_0wUlTdZmZpHjg7k

    Joined:
    Nov 15, 2023
    Posts:
    1
    I want to set the bots to only shoot at each other, too. I find someone asked the same question 21 days ago but no reply. How can I do it by Enemy AI?
     
  25. rc82

    rc82

    Joined:
    Jan 28, 2020
    Posts:
    44
    They are set up to shoot the player.

    You need to add a targeting function where it looks for enemy players. Usually I put a "team a" and "team b" layer for a collider that's used for raycasting to see if they're in line of sight. Then they aim and you can use that or other colliders to detect impacts.

    It's definitely possible, I've done it.
     
    Viniterra likes this.
  26. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    193
    Hi, for a faster response, you can always reach me trough the support form:

    Support for the Enemy AI package

    This question was already covered, in this same forum thread, here (answer 1), and here.