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] Emerald AI 3.2 (New Sound Detection) - The Ultimate Universal AAA Quality AI Solution

Discussion in 'Assets and Asset Store' started by BHS, Jun 26, 2015.

  1. alex_1302

    alex_1302

    Joined:
    Aug 20, 2019
    Posts:
    54
    Hi. i want to know how can i make the following with emerald ai:
    i want that an emerald npc run to the player when it detecting him until it reach a distance between 10 and 20 meters from the player, but and here is the tricky part for me: i need that the npc attack (ranged attack) the player while is moving towards him. How can i do that with emerald ? . Thanks in advance.
     
    Last edited: Feb 23, 2020
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @Pandur1982 I found the problem. Basically, that combat text in that demo scene is not part of the built-in EmeraldAISystem. It is a special script that is being executed for the demo player object. And it only activates when you press the mouse button to attack and register a hit. Since the demo player is being used instead of a player that is integrated through the normal way, the only way for combat text to work in that demo scene is to instantiate combat text manually. However, since the DamageAI Playmaker action is also bypassing the normal channels, it also will not instantiate combat text. So, I will add a flag to allow you to choose whether or not you want combat text and, if so, to manually instantiate the combat text when the AI is damaged.
     
  3. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @Pandur1982 Here is an updated package with the ability to turn combat text on/off in the DamageAI action.
     

    Attached Files:

    Pandur1982 and dsilverthorn like this.
  4. alex_1302

    alex_1302

    Joined:
    Aug 20, 2019
    Posts:
    54
    Hi Guys. I think i found a way to make an emerald ai to fire a ranged attack while is moving towards its target. if someone is interested, i made this change:
    in the emeraldaAIbehaviors.cs inside the method AttackState() you must comment the line:

    if (EmeraldComponent.m_NavMeshAgent.remainingDistance < EmeraldComponent.m_NavMeshAgent.stoppingDistance && !EmeraldComponent.m_NavMeshAgent.pathPending && !EmeraldComponent.IsMoving && !EmeraldComponent.Attacking)

    and above it you must put the following code:

    bool readyToAttack = false;
    if (EmeraldComponent.WeaponTypeRef == EmeraldAISystem.WeaponType.Ranged)
    {
    if (!EmeraldComponent.m_NavMeshAgent.pathPending && !EmeraldComponent.Attacking)
    readyToAttack = true;
    //if (EmeraldComponent.m_NavMeshAgent.remainingDistance < EmeraldComponent.m_NavMeshAgent.stoppingDistance && !EmeraldComponent.m_NavMeshAgent.pathPending && !EmeraldComponent.IsMoving && !EmeraldComponent.Attacking)
    }
    else
    {
    if (EmeraldComponent.WeaponTypeRef == EmeraldAISystem.WeaponType.Melee)
    {
    if (EmeraldComponent.m_NavMeshAgent.remainingDistance < EmeraldComponent.m_NavMeshAgent.stoppingDistance && !EmeraldComponent.m_NavMeshAgent.pathPending && !EmeraldComponent.IsMoving && !EmeraldComponent.Attacking)
    readyToAttack = true;
    }



    }
    if (readyToAttack)
     
    Last edited: Feb 24, 2020
    thaomoua, SamRock and dsilverthorn like this.
  5. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    275
    @magique Big thx for your work and time that is the perfect Function to use Emerald AI with Playmaker, the Combat Text works great now.I have tested on my Project ,works very great and that save me a many time , iam very happy now. :D
     
    magique likes this.
  6. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    I have a weird issue.

    I have a pet in the scene, which works fine. But now added animals and they will not move. Only idle animations play.
    I've gone step by step with the tutorial. I've tried RM and Navmesh but can't get them to move.:(

    I know I must be missing something, but can't figure it out.:confused:

    Since the pet is working, shouldn't the rest work as well?
    I've even tried turning one into a pet, but no luck. They just stand there and idle.
     
  7. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    Are they supposed to attack you? If so, it could be a layer issue. Make sure your player's layer is referenced in the AI's settings. In addition, make sure your player's tag is set in the Player Tag section of the Detection tab.
     
    dsilverthorn likes this.
  8. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Probably not this week, but most likely sometime next week.
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Thanks for the suggestion. This sounds like a good addition for the backup mechanics. I'll look into this for the update after 2.4.
     
    AaronVictoria likes this.
  10. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    For 1) Could you please guide me which event I can use to add the script to detect when the player is idle and the Pet should stop following me now? I looked at the API function and couldnt find something that would help.
     
  11. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You need to define what you mean by player being idle. Since player systems are not part of Emerald AI, it's up to you to decide what this means. Then it's quite another matter to detect that condition and change the pet behavior appropriately.
     
  12. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    Not attacking for this one. Just trying to get some wandering animals in the woods etc.

    Trying to get some farm animals that just need to graze and walk around as a part of the scenery. I could set up waypoints and do it that way, but just wanted them to be random wandering over an area as this is the main area and trying to stay away from pattern movements.

    So far they just stand there and go through the idle animations. I have a navmesh working and have re-baked to check but I'm stuck on what to look for now. I'm fairly new to Emerald, I picked it up a while back, but now I'm trying to get it working and running into road blocks.
     
  13. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Do you have Dynamic Wander turned on? If not then they will just stand there and never go anywhere.
     
    dsilverthorn likes this.
  14. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Possible to integrate this with oculus quest and the controllers it uses?
     
  15. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    Yep. I'm wondering if something happened to my terrain.

    I had AI working a while back and took them out to finish the design. Now adding them back doesn't work. Neither prefabs that I made before I removed them nor creating from scratch works.

    I'm going to do some testing with a new scene and see if something went wrong.

    My navmesh shows up and I've tried to clear and bake but no change. It seems I always get the weird things happening to me.:confused:

    This will suck if its a terrain navmesh problem, I've been designing this scene for 2 months. Is there a way to strip the existing navmesh and add a new one? That is the only thing I can think of as the problem. But it is weird that the pet AI works.
     
  16. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Can you confirm if the prefab Fallen Guardian AI works in your scene?

    [EDIT]
    Also, a good practice is to create a new scene completely from scratch with just a static plane for the ground and create and test your AI there. If it doesn't work even in that basic environment then something else serious is going on. And also just check the provided demo scenes to see if they work.
     
    Last edited: Feb 25, 2020
  17. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    Well, if the player say, hasn't moved for x distance then I would consider him being idle in a position. I was thinking of using the OnDetection event and tweak it for this purpose. If already covers this logic to check for player. So then I want my pet or companion AI start wandering in a fixed radius. Could you guide me how?
     
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    So, the AI would stop following and go into a wander mode?
     
  19. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    Thanks. Next step is the test scene and then a new blank scene to see if I can narrow it down.
    Keeping my fingers crossed. :)
     
  20. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    Demo scenes work. Problem is in my landscape.

    Edit:
    Continued testing. All animal AI will not walk in scene. In demo scene, I added my animal prefabs and they walked.

    Something is wrong with my scene. I cleared and baked navmesh again, no change.
    I don't know what to check next. And I don't want to re-create the scene that has taken months to get to this point.

    How do I delete a navmesh data, other than just clearing from the navigation tab?
    I am thinking that there is a problem with an old navmesh data that did not get removed. This is my guess. But it could be something else, I don't know what else though.:confused:

    I have proven it is not Emerald, but something in my scene- must be the terrain.

    Anyone have any ideas?
     
    Last edited: Feb 26, 2020
  21. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I don't know what character controller you're using so I have no idea how to tell whether the character is idling or not. You could check the player's (the AI's follower) velocity though using:
    Code (CSharp):
    1. velocity = ((EmeraldComponent.CurrentFollowTarget.position - previous).magnitude) / Time.deltaTime;
    2. previous = EmeraldComponent.CurrentFollowTarget.position;
    This would need to be handled with an external script though. Because a pet AI is programmed to stay stationary when arriving to their follower's destination, more may need to be done to allow the AI to wander around while the player is stationary. I can certainly look into this feature with a future update though.
     
  22. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    What are your NavMesh settings? Can you see the generated navmesh when you are using the Navigation tab? Is your terrain marked as Static as explained here: https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Baking-NavMesh

    You can clear the NavMesh with the clear button within the Navigation tab.
    ClearNavMesh.png
     
  23. Alexandus

    Alexandus

    Joined:
    Sep 5, 2012
    Posts:
    25
    Hey there - what features / fixes are inbound in 2.4?
     
  24. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    Yes when the player starts moving he would resume to being a companion AI.

    Here is the same behaviour I codes before using Emerald AI. I just need to know where to integrate the code and switch to wandering
     
    Last edited: Feb 26, 2020
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I see @BHS already responded, but I think it's possible to do this by changing the companion behavior dynamically. It think it could be done with my Playmaker actions or you could simply hijack the code from the actions and use in your own script.

    Basically, you would first determine if the player is idle with whatever conditions you've already decided on. Then you would change the AI behavior so it's no longer a companion and set it's wandering to dynamic wander. Then when the player is not idle, switch it back to a companion. I haven't tried it, but I think it could work.
     
  26. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    Yes it would definitely.. only issue is I dont know where to add the code in the EmeraldAI system. if only i could override the behavior class. But that would mean modifying the E-AI code and risking of losing it to future updates.
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You don't need to modify code in the EmeraldAI system. The code can be in a separate script that references the object containing the Emerald AI scripts.
     
    SamRock likes this.
  28. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    What are your NavMesh settings?
    I have tried it with the default settings.Then tried a custom one. Same result. The pet runs around but any other type does not.

    Can you see the generated navmesh when you are using the Navigation tab?
    Yes, terrain has a blue NavMesh when Show NavMesh is checked

    Is your terrain marked as Static?
    Yes

    I have cleared and baked new several times. I think, maybe, one of the old cleared meshes did not clear and is causing a problem. But I don't know, something is wrong with my NavMesh.
     
  29. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    alex_1302 likes this.
  30. alex_1302

    alex_1302

    Joined:
    Aug 20, 2019
    Posts:
    54
    hi guys. i want to ask something: i need to enable or disable an EAI gameobject based on its distance from the players. i wrote my own enable/disable component but i watch that when EAI gets disabled (setActive(false)) and then get it activated again (setActive(true)) the EAI dont attack anymore. someone know how can i reactivate it to initial State like it was it just spawned ? Thanks in advance.
     
    Last edited: Feb 28, 2020
  31. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    I think you can call the ResetAI event on the EmeraldAIEventsManager.
     
    alex_1302 likes this.
  32. alex_1302

    alex_1302

    Joined:
    Aug 20, 2019
    Posts:
    54
    Thanks Deckard_89. Effectivelly i finally end up using ResetAI. but after use it, my code have to restore the currentHealth and the starting Position to adapt it to my needs. Thanks very much. :)
     
  33. Alexandus

    Alexandus

    Joined:
    Sep 5, 2012
    Posts:
    25
  34. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    Question about SetCombatTarget()

    I can't seem to get it to work, it gives me the following error. The player is the target but when this script is called its saying no target.

    NullReferenceException: Object reference not set to an instance of an object
    EmeraldAI.Utility.EmeraldAIDetection.DetectTargetType (UnityEngine.Transform Target, System.Nullable`1[T] OverrideFactionRequirement) (at Assets/Emerald AI/Scripts/Components/EmeraldAIDetection.cs:991)
     
  35. cepoimario280135

    cepoimario280135

    Joined:
    Jan 24, 2020
    Posts:
    12
    i am getting
    IndexOutOfRangeException: Index was outside the bounds of the array.
    EmeraldAI.EmeraldAISystem.Update () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:959)

    can't figure out why , does someone knows something about his?
     
  36. cepoimario280135

    cepoimario280135

    Joined:
    Jan 24, 2020
    Posts:
    12
    I am also implementing the system in my multiplayer game and the issues is whenever i destroy the a player the system throws MissingReferenceException: The object of type 'Transform' has been destroyed , how can i properly remove the target before destroying ?
     
  37. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I just tested this and everything is working properly on my end. How are you assigning the target to SetCombatTarget? You should check if the target is null before calling the SetCombatTarget function.
     
  38. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    This is most likely a missing animation. Go through your animations in the Animation tab and make sure there's no missing animations.
     
  39. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS Is this the week?!
     
  40. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I've fixed this with the upcoming version 2.4, but for now, you need to call ClearTarget(). An example and more information regarding this can be found here: https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Emerald-AI-API#cleartarget
     
  41. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    That's the plan :)
     
    julianr, Raul_T and dsilverthorn like this.
  42. Kojote

    Kojote

    Joined:
    May 6, 2017
    Posts:
    181
    Hi,

    Unfortunately, I still haven't gotten anywhere with this problem. I once made a video. The green Ray is the Ray for the damage of the script "DamageAISystem.cs".



    (Sorry for the poor quality of the video. The direct link shows a better quality than here in the forum.)

    As you can see the Cougar does damage from time to time. But much less than it should be. The Ray hits the collider of the Cocodile, but the damage is very rarely registered.

    Can you help me here?

    EDIT:

    Another problem. I have a footstep script that leaves footprints. To trigger them, I attached Sphere Colliders to the feet of the Enemys. But it seems that EmeraldAI deactivates this Sphere Collider when the program starts.

    Can you tell me why and how I can circumvent this?
     
    Last edited: Mar 6, 2020
  43. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS A couple of things.. One please see my PM and when you get done with 2.4.1, can you please let us know what is on the next release docket?
     
  44. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    Is there a way to get ai to track enemies and attack them (like scout out for nearby enemy) ?
     
  45. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    275
    Hello all i working at the moment on a littel rpg and i use inventory pro for the inventory , i have create a littel bride from inventory pro to the EmeraldAIPlayerHealth Script. Now is my Problem to bring some Stats like Armor from the cloth or other states from the clothes what the player can equip to reduce the damage.Have some one a Idea for that? My Idea is for the Armor a Vlaue from min 1 to max 100 as procent.On 100 Armor the Player get no damage on 50 Armor player became the half of the damage and so one.
     
  46. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    What I do is once the enemies spawn I target the player so its not null, at least it shouldnt be. I can use the move to target one and it works fine, but thats to the last location the player was (I use that for if the player shoots) I did a debug and it finds the player so not sure why its saying null.
     
  47. RossHopkins

    RossHopkins

    Joined:
    Oct 28, 2016
    Posts:
    7
    Im having a problem with getting animals to flee. It doesnt seem to work. I set up everything to the targeting and tagging are triggered by tag: player on layer:water and aggressive works. But when I set to caustious or passive and coward they dont flee they wander but dont flee.
     
  48. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Hey there,

    I would recommend using a different method for damaging your AI. The included system is meant as an example and may not suit every system's needs.

    One method I would recommend is an angle and distance check to the target, rather than a raycast as it can sometimes miss like in your video.

    Attach this to your player instead of the included Emerald AI one to see if it works better.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using EmeraldAI;
    5.  
    6. public class DamageAIByAngle : MonoBehaviour
    7. {
    8.     public LayerMask AIMask;
    9.     public int DamageAmount = 5;
    10.     public int DamageRange = 6;
    11.     public int DamageAngle = 45;
    12.     public KeyCode DamageButton = KeyCode.Mouse0;
    13.    
    14.     void Update ()
    15.     {
    16.         if (Input.GetKeyDown(DamageButton))
    17.         {
    18.             Collider[] hitColliders = Physics.OverlapSphere(transform.position, DamageRange, AIMask);
    19.  
    20.             for (int i = 0; i < hitColliders.Length; i++)
    21.             {
    22.                 Transform TempTarget = hitColliders[i].transform;
    23.  
    24.                 Vector3 targetDir = TempTarget.position - transform.position;
    25.                 float angle = Vector3.Angle(targetDir, transform.forward);
    26.  
    27.                 if (TempTarget.GetComponent<EmeraldAISystem>() != null && angle <= DamageAngle)
    28.                 {
    29.                     TempTarget.GetComponent<EmeraldAISystem>().Damage(DamageAmount, EmeraldAISystem.TargetType.Player, transform, 500);
    30.                 }
    31.             }        
    32.         }
    33.     }
    34. }
    35.  
    As for your footprints, I would recommend an Animation Event on your AI's walk and run animations. They are more consistent than colliders and more performant. The process should be the same as adding footstep sounds like in this Emerald AI tutorial video, but instead, you would create your footsteps:
     
    Pandur1982 likes this.
  49. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I've responded to your PM. :)

    I don't have any official release notes for what will be in updates after 2.4, but I will post them here when they're ready.
     
    SickaGames1 likes this.
  50. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I'm not sure I understand exactly what you are asking. If an AI detects any opposing AI, it will react according to its behavior type. An AI won't just follow an AI by default, but this can be added via custom code.

    You can check out Emerald AI's API to see if it will help you find some useful built-in functions: https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Emerald-AI-API