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. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Yes, it should work. You just need to call the AI’s damage function. More information on this can be found on the Emerald AI documentation.
     
  2. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I can reach out to the developer to see if I can get a copy of the asset to add support. It’s certainly possible, you just have to damage Emerald AI agents when hit by the Unreal FPS bullets and alter the EmeraldAIPlayerDamage script to damage the Unreal FPS health.
     
    Oderus_Urungus likes this.
  3. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    were would i need to to call this ?

    Current Damage Script

    Code (CSharp):
    1.     public float damage;
    2.  
    3.     private int hitRange = 1;
    4.  
    5.     public bool isDead = false;
    6.  
    7.  
    8.     private void Start()
    9.     {
    10.     }
    11.  
    12.  
    13.     void Update()
    14.     {
    15.         if (Input.GetKeyDown("e"))
    16.         {
    17.             Attack();
    18.  
    19.         }
    20.  
    21.  
    22.  
    23.  
    24.         void Attack()
    25.         {
    26.             RaycastHit hit;
    27.             Vector3 forward = transform.TransformDirection(Vector3.forward);
    28.             Vector3 origin = transform.position;
    29.  
    30.             if (Physics.Raycast(origin, forward, out hit, hitRange))
    31.             {
    32.                 if (hit.transform.gameObject.tag == "Player")
    33.                 {
    34.                     hit.transform.gameObject.SendMessage("PlayerDamage", 50);
    35.                     GetComponent<PlayerVitals>().curExp += 50;
    36.                     GetComponent<PlayerVitals>().GetComponent<EmeraldAI.EmeraldAISystem>().Damage(50, EmeraldAI.EmeraldAISystem.TargetType.Player);
    37.  
    38.                     }
    39.                 }      
    40.  
    41.                 }
    42.  
    43.  
    44. current player health:
    45.  
    46.   private Animator anim;
    47.  
    48.  
    49.  
    50.     public bool isDead = false;
    51.  
    52.     public Slider healthSlider;
    53.     public int maxHealth;
    54.     public float curhealth;
    55.     public int healthFallRate;
    56.  
    57.     public float sec = 20f;
    58.    
    59.     private void Start()
    60.     {
    61.         anim = GetComponent<Animator>();
    62.  
    63.  
    64.         curhealth = maxHealth;
    65.         healthSlider.maxValue = maxHealth;
    66.         healthSlider.value = maxHealth;
    67.  
    68.         thirstSlider.maxValue = maxThirst;
    69.         thirstSlider.value = maxThirst;
    70.  
    71.    
    72.         hungerSlider.maxValue = maxHunger;
    73.         hungerSlider.value = maxHunger;
    74.  
    75.     }
    76.  
    77.  
    78.     public void PlayerDamage(float damage)
    79.  
    80.     {
    81.         if (curhealth > 0)
    82.         {
    83.             if (damage >= curhealth)
    84.             {
    85.                
    86.                 Dead();
    87.             }
    88.             else
    89.             {
    90.                 curhealth -= damage;
    91.                 healthSlider.value -= damage;
    92.  
    93.             }
    94.         }
    95.             }
     
  4. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    @BHS Got home from work, set it all up, fix was easy, and lovin it, no more console errors. Big thnx for the help, i cant stop using it, think im going to be up real late tonight..lol

    The update features are rock solid, damn you guys are great :)
     
  5. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    It is just him lol
     
  6. Oderus_Urungus

    Oderus_Urungus

    Joined:
    Jun 8, 2017
    Posts:
    96
    That would be great! I want to use Emerald AI with it so badly.
     
  7. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    Traced last nights problem, my changes to scripts (comment or uncomment) werent being saved by Visual Studio, dont know why, as it saved today...
     
  8. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    What specifically are you trying to do and where is this script attached? If it’s attached to your player, you need to get the reference to the object hit, not the reference to the player to cause damage:
    Code (CSharp):
    1. hit.collider.GetComponent<EmeraldAI.EmeraldAISystem>().Damage(50, EmeraldAI.EmeraldAISystem.TargetType.Player);
     
  9. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    31
    I can't get into my unity account to access the latest version, can I provide you my invoice and whatever info I need for a download?
     
  10. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    i have both to my player. The cow damages my player if i use the emerald ai player health, but i want it to work with my player created script not emerald
     
  11. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Great to hear you got it all figured out and that you're enjoying 2.3! :)
     
    warthos3399 likes this.
  12. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    is their any more tutorials that explain the AI - player damage in more detail because my cow ai chases my animal player but neither can damage each other? i am getting a bit confused :(
     
  13. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I don't offer direct downloads, sorry. If you can't access your account, you should contact Unity and I'm sure they can help you resolve it.
     
  14. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Player damage is all handled within the EmeraldAIPlayerDamage script and its SendPlayerDamage function. When a player object is damaged, this script is automatically applied to your player. You can use this script to damage your player, even with calls to custom functions and scripts.

    Code (CSharp):
    1. public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent)
    2. {
    3.    //The standard damage function that sends damage to the Emerald AI demo player
    4.    DamagePlayerStandard(DamageAmount);
    5. }
    If you want to add a custom function to damage your own player system, you could add it within this function:

    Code (CSharp):
    1. public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent)
    2. {
    3.    //The standard damage function that sends damage to the Emerald AI demo player
    4.    //DamagePlayerStandard(DamageAmount);
    5.          
    6.    //Damage your custom player by calling the added function
    7.    DamageCustomPlayer(DamageAmount, Target);
    8. }
    9.      
    10. //Damage your custom player by using your SendMessage PlayerDamage
    11. void DamageCustomPlayer (int DamageAmount, Transform Target)
    12. {
    13.    Target.SendMessage("PlayerDamage", DamageAmount);
    14. }
    15.  
    Emerald AI's API can be found here: https://docs.google.com/document/d/1ns8m7Ol_gaKeYJ3YbaRjDy09xG98UoIXKCaWLGJeg74/edit
     
  15. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah right and the emerald ai system has a build in health system ?
     
  16. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    31

    No biggie I'll buy another copy, I love this asset and seeing this huge update made me want to give it a try again! Thanks anyways!
     
  17. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Yes, and to view or alter the current health, you would use:
    Code (CSharp):
    1. YourObjectReference.GetComponent<EmeraldAI.EmeraldAISystem>().CurrentHealth
    To damage the AI's current health, you would the following as you did in your above code:
    Code (CSharp):
    1. YourObjectReference.GetComponent<EmeraldAI.EmeraldAISystem>().Damage(DamageAmount, EmeraldAI.EmeraldAISystem.TargetType.Player);
     
  18. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah right would that be by editing the emerald system?
     
  19. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    You don't need to edit any Emerald system code to call those.
     
  20. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah so call them in the damage script ?
     
  21. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    The code to damage the player goes in the EmeraldAIPlayerDamage script and the code to damage the AI goes on your player’s Attack function where you use the hit object reference to call the AI’s damage function.
     
  22. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Always see integrations stuff. With the AI events. Would it be difficult to add in a unityevent for on attack, but sent to the target? Might simplify some intergration? Offer another route. But dk.
     
  23. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    @SickaGamer and @BHS if i dont comment out CheckAnimationEvents(); and CheckForMissingAnimations();, this is what i get (right after import finishes):

    Im going to re-read the update instructions once more, to make sure i didnt miss something, then wipe EAI completely and import complete and fresh...
     
    Last edited: Sep 26, 2019
  24. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    It might be more work but the solid solution, is to just set in the animations. One thing ive learned, sometimes, you just gotta sit down and grind if you want quality. Imo
     
    warthos3399 likes this.
  25. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    Totally agree, and i can shut them off, just didnt think they would be Red Errors, i thought perviously they were yellow. No biggie, as i can shut them off anyway, just wanted to post that pic to show what i get if i dont comment out things :)
     
    Last edited: Sep 27, 2019
  26. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    on my AI it keeps saying failed to call animation event SendPlayerDamage of class emeraldaiplayerdamage Any ideas on what seems to be going wrong ?
     
  27. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    Don't worry too much about the color. They are red because BHS made them Debug.LogError's instead of Debug.LogWarning's which are yellow. Best course of action is to setup the animations. Otherwise, you can doubleclick on the error message in the console and your editor (mono/Visual Studio) will open at the location of the debug line.

    Mark
     
  28. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    They also dont repeat, just on start, so i dont think its a big impact on performance
     
    warthos3399 likes this.
  29. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    @BHS I have another odd one. I have set up 4 Companion AI's, all with Melee and Ranged. Each works great on their own, and coupled with any other. Drop 3 or all 4 in together, they work fine for a while, then one of them will lock up in combat mode, and the console fills with errors after all of the bad guys are killed.

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    EmeraldAI.Utility.EmeraldAIDetection.SearchForTarget () (at Assets/Emerald AI/Scripts/Components/EmeraldAIDetection.cs:851)
    EmeraldAI.EmeraldAISystem.Update () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:1114)

    Here is a video demonstrating this challenge: (Warning, 84MB) <DELETED>
    It also shows the voice over drop off of PlayIdleSound.
    Mark
     
    Last edited: Sep 27, 2019
  30. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS will hopefully be patching this soon
     
    warthos3399 likes this.
  31. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    Ya know how it goes, you see red console errors and your brain says "stop, somethings wrong, fix it", lol. Loving the new Needs System, @BHS great job, nice to see dinos go to actual resources to eat when hungry :)
     
  32. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Dearlord, i dont stop to fix red errors till i have about 500 lol
     
    warthos3399 likes this.
  33. UDN_68a3a08d-b184-416c-8d9f-f1f5b1bedf54

    UDN_68a3a08d-b184-416c-8d9f-f1f5b1bedf54

    Joined:
    Jul 29, 2018
    Posts:
    4
    Hey @BHS great asset, i'm facing an issue that if i shoot AI outside its detection trigger logically it should attack me if its Behavior is Aggressive/Cautious and confidence level is Brave/Foolhardy. It just don't attack keeps on playing Combat idle animation on loop and then it dosent matter if i go close it it wont attack me also, but if i go in trigger distance it works fine like it should. What could i have done wrong, im not missing any animations.
     
  34. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    There’s a UnityEvent for attack on the AI’s end. To have it sent to the target, you could have a function that grabs the AI’s current target to invoke an event or call code from the target at the time of the AI’s attack event.

    The integration process is already simplified by using the EmeraldAIPlayerDamage script so none of the systems’ code has to be altered.
     
  35. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Those messages are happening during Start and can’t happen during or after the import process. You also don’t have Clear on Play enabled on your Console so the messages you are seeing may be from when you were in runtime during a previous test.

    The messages you are seeing are not error messages. They are simply debug logs telling you that you are missing animations or animation events. They don’t affect performance because they are only called once on start. Commenting out the functions I mentioned should have stopped them from appearing. If you reimported the asset, you will need to comment them out again. Also, you had mentioned that VS wasn’t properly compiling your script changes. Ensure that your changes are being properly saved.
     
    warthos3399 likes this.
  36. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    The animation event name is SendEmeraldDamage not SendPlayerDamage. This needs to be created on your AI’s attack animations. See the video here for a tutorial:
     
  37. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    done the event thing and the error disapeared :) but
    Current player health still not dropping when AI hits it am i missing something?(player animal is using a capsule collider not sure if this makes a difference)

    Current health script
    Code (CSharp):
    1.  
    2.  
    3.        private Animator anim;
    4.         public int CurrentHealth;
    5.         public void DamagePlayerStandard(int DamageAmount)
    6.  
    7.         {
    8.             CurrentHealth -= DamageAmount;
    9.             healthSlider.value -= DamageAmount;
    10.  
    11.             if (CurrentHealth <= 0)
    12.             {
    13.                 if (DamageAmount >= CurrentHealth)
    14.                 {
    15.  
    16.                     Dead();
    17.                 }
    18.             }
    19.  
    20.  
    21.         }
     
    Last edited: Sep 27, 2019
  38. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    Damage Script

    Code (CSharp):
    1. public int DamageAmount = 50;
    2.         private int hitRange = 1;
    3.  
    4.         private Animator anim;
    5.  
    6.  
    7.         public void SendPlayerDamage(int DamageAmount, Transform Player, EmeraldAISystem EmeraldComponent)
    8.         {
    9.  
    10.             //Damage your custom player by calling the added function
    11.             DamagePlayerStandard(DamageAmount);
    12.  
    13.         }
    14.         void DamagePlayerStandard(int DamageAmount)
    15.         {
    16.             if (GetComponent<EmeraldAIPlayerHealth>() != null)
    17.             {
    18.                 GetComponent<EmeraldAIPlayerHealth>().DamagePlayerStandard(DamageAmount);
    19.             }
    20.         }
     
  39. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Hey Mark. Thanks for providing a video with the issues you are having. It makes it easier to identify the issues you are having.

    The null reference error shouldn't be happening as Emerald AI doesn't destroy any objects so that's happening externally somewhere. If an AI dies, or is even destroyed, the agents will search for a new target. Are you destroying the AI around the time of death such as a despawn system? Is the object 'GameObject' it's mentioning anything related to your scene? It could be that the AI are picking up an object and setting it as a target when they shouldn't be (like an object marked with the AI layer and tag).

    I'll look into the sound cutting out. I'm pretty sure it's related to the walking or running sounds switching the volume before the idle sound finishes playing.

    I have a fix coming soon that will address this and some of the other issues that have been happening.
     
  40. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    It's because you are calling the demo player health function that's reducing the demo health system's health and not your player health script/value. Are the 2 scripts you posted two different scripts or all code you've added to the EmeraldAIPlayerDamage script?
     
  41. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS when is your update for EAI?
     
  42. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    @BHS added my damage script to the emeraldAIPlayerDamage and my health script to the emeraldAIPlayer health. Two seperate scripts
     
  43. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    You are right, I do have an external script on every AI to remove their mini-map marker from the screen immediately and sink their corpse slowly into the ground 30 seconds after they die, then destroying them. Should I be removing them from the potentialTargets list before destroying them or doing something differently?
     
  44. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    The 2.3.0.2 update will be submitted sometime today. This update is small, but should resolve the issues some users have been having with version 2.3.
     
  45. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    All player damage is sent to the SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent) function. If you are adding custom code, you need to ensure your function is being called from within this function. If you are using the included DamagePlayerStandard function, also ensure this is still being called within the SendPlayerDamage function. Try using a Debug.Log to see if it's even being called. Have you tried using the included player health script to ensure everything is working correctly?
     
  46. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    yeah when i use the provided script it works but its when i go to add my stuff
     
  47. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    The AI should be removed from the potentialTargets list after they are dead so I'm not entirely sure what's happening. You could check with some debugging to see if they are still present when they are destroyed though. What's interesting is that the code that's causing the error is only for the aggro feature when an AI is switching to a random target so I'm not sure what's triggering it if the AI are dead. I haven't been able to recreate it on my end.
     
  48. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    @BHS im all set, im good (clear on play wasnt selected, as thats a copy/test project of the game). One question any info/docs on the new turning anumation?
     
  49. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    124
    Fun Friday post- Pretty cool AI head look. :) Companion Dog on the way. lol
     

    Attached Files:

    warthos3399 and BHS like this.
  50. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    You can find the new Turn Animation Type under the Movement Settings. It explains the differences between the two options from within the Emerald editor.
     
    warthos3399 likes this.