Search Unity

[RELEASED] Emerald AI 2.3 - The Ultimate Universal AAA Quality AI Solution

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

  1. marco-maceratesi

    marco-maceratesi

    Joined:
    Sep 20, 2013
    Posts:
    9
    Realistic FPS + Emerald AI 2.3.0.2 problem:
    When I shoot at an enemy before the enemy detect the player, the detected object is the weapon held or the bullet, causing the enemies to not damage player.
    For example M1911 or SHOTGUN...
    How can I prevent this strange behavior?
    Thanks in advance
     
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    @BHS I'm seeing an issue with the Equip Animations not working in this version. My AI was working correctly previously, but now when it equips the weapon, the weapon object does not turn on. I double checked that both the EnabeWeapon and DisableWeapon events are still there and the weapon object is set correctly. I'll check the code later, but you might be able to figure out what's wrong quicker.
     
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    Hey there. You should be able to import version 2.3.0.2 without having to remove Emerald AI from your project, but create a backup of your project just in case.
     
    combatsheep likes this.
  4. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    Right underneath this:
    Code (CSharp):
    1. if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody))
    2. {
    3.    rigidbodies.Add(col.attachedRigidbody);
    4. }
    Add the following:
    Code (CSharp):
    1. if (col.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>())
    2. {          
    3.    col.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>().Damage(20, EmeraldAI.EmeraldAISystem.TargetType.Player);
    4. }
     
    FrostedBrain likes this.
  5. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    Thanks, I'll look into adding something like this with the next update.
     
  6. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    18

    Perfect! That's just what I needed thank you.
     
  7. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    now that i got my player damaging my AI my AI is not damaging my player even when hitting it? happened after the update :(
     
    Last edited: Oct 7, 2019
  8. marco-maceratesi

    marco-maceratesi

    Joined:
    Sep 20, 2013
    Posts:
    9
    I'm sorry I forgot to mention the Unity version: 2019.2.8.
    I also attach a video demo to better explain the problem.



    A little help please :(
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    You need to ensure that only the FPS Player object has the Player Tag and Player Layer. You also need to make sure no other unneeded layers are using the AI's Detection Layers . If not, Emerald AI will pick them up when it's searching for targets. Do your RFPS's weapon objects have colliders on them?
     
  10. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    turns out my cow is taking damage but it still keeps on running how can i fix this? Fixed
     
    Last edited: Oct 8, 2019
  11. combatsheep

    combatsheep

    Joined:
    Jan 30, 2015
    Posts:
    94
    Thank you!:)
     
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
  13. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    does anyone know how to make it so that my player can pull my AI to the ground? like when a lion attacks a zebra?
     
  14. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    Which previous version? I changed the Equip and Unequip function with the 2.3 version to include a string for the weapon type you would like to enable or disable. This is controlled via the String parameter within the Animation Event. These string values are either Melee or Ranged.
     
  15. CDVoss

    CDVoss

    Joined:
    Jun 24, 2019
    Posts:
    3
    Hello BHS -
    I dont know if you would look into it in the future.
    But the obstruction timer doesn´t seem to work anymore on ranged AI. (I dont have any interfering scripts on the AI - So it should work as default).
    Ive set it to 8 seconds in my example - But the ai moves immediately towards the player when encountering an obstruction.
     
  16. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    Ahh, I see. I wasn't aware of that. I will see if that helps.

    [EDIT]
    Yes, that works now. Thanks for the new information.
     
    Last edited: Oct 9, 2019
  17. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    how can i get my player to give xp ? want different ai to give different amounts
     
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    You would have to code this sort of functionality yourself. You could add an OnDeath event handler and point to a script that has OnDeath function. That script could also define the XP value for the AI. And then you just have to apply that XP to wherever you are accumulating it.
     
  19. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    i got some code i added onto the emeraldAIPlayerdamage so when it hits ai it gains xp but i don't want every ai to give say 50 xp?
     
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    You want XP added for every hit? Not just when the AI dies?
     
  21. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    Here is a sample script that adds XP on damaged as well as on death. Simply attach the script to your AI and hook up the OnDamaged and OnDeath events to the appropriate functions. You'll need to add in your own code in place of the TODO items so that the xp values are actually applied to your character.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AIHelper : MonoBehaviour
    6. {
    7.     public int xpOnDamaged;
    8.     public int xpOnDeath;
    9.  
    10.     public void OnDamaged()
    11.     {
    12.         // TODO: call my function that adds xpOnDamaged value to player's XP
    13.     }
    14.  
    15.     public void OnDeath()
    16.     {
    17.         // TODO: call my function that adds xpOnDeath value to player's XP
    18.     }
    19. }
    20.  
     
    combatsheep likes this.
  22. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    only want xp when ai dies. Like for example pig would give say 20 xp on death but elephant would give 50xp upon death
     
  23. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    902
    Code it... You will feel better about yourself! or you can check out Game Creator and download the add ons.
     
  24. pccross

    pccross

    Joined:
    Jun 20, 2015
    Posts:
    96
    I've just started using Umotion Pro to improve my game animations. Was wondering, are there any tips with using its animations alongside EAI? For instance, if I want a wandering AI to break from his path to perform a custom action (animation), would I need to disable the EAI temporarily, and play the custom animation via script, and then re-enable EAI after?
     
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    Then you just need my base script with only one function as follows:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class AIHelper : MonoBehaviour
    5. {
    6.     public int xpOnDeath;
    7.     public void OnDeath()
    8.     {
    9.         // TODO: call my function that adds xpOnDeath value to player's XP
    10.     }
    11. }
    When you attach the script to an AI, just set the xp value for that AI. And you'll have to add your own code to actually update the player XP. This example script is really what you should use as the basis for all your AI. Expand on it to handle all your unique AI needs. Put other event handlers in there as needed and hook them up to the Emerald AI event system.
     
  26. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    ah right will check this out thank you :) normally when i try add code on death event it stops the ai being damaged
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    It should work perfectly. This is exactly how I do it. My AI script has the same OnDeath hooked to the OnDeath event and it calls into my GameMaster component to add xp to the player and it works beautifully.
     
  28. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    tried that script and added this to my to give xp to my player but not giving xp to player
    Code (CSharp):
    1.         GetComponent<XPGiver>().experience += 100;
    2.  
    .



    this is my xp script for player to gain xp (atm pressing a button gains xp to player) want to change it though so gains only on AI death

    Code (CSharp):
    1.  
    2.         //Variables
    3.  
    4.         public int level;
    5.         public float experience;
    6.         private float experienceRequired;
    7.  
    8.         public float hp;  // FOR TESTING PURPOSES
    9.  
    10.  
    11.  
    12.         //Methods
    13.         private void Start()
    14.         {
    15.             level = 1;
    16.             hp = 100;
    17.             experience = 0;
    18.             experienceRequired = 100;
    19.         }
    20.  
    21.         private void Update()
    22.         {
    23.             Exp();
    24.  
    25.             if(Input.GetKeyDown(KeyCode.E))
    26.             {
    27.                 experience += 100;
    28.             }
    29.         }
    30.  
    31.         void RankUp()
    32.         {
    33.             level += 1;
    34.             experience = 0;
    35.  
    36.             switch (level)
    37.             {
    38.                 case 2:
    39.                     hp = 200;
    40.                     experienceRequired = 200;
    41.                     break;
    42.  
    43.                 case 3:
    44.                     hp = 300;
    45.                     experienceRequired = 300;
    46.                     print("You have hit Level 3");
    47.                     break;
    48.             }
    49.         }
    50.  
    51.         void Exp()
    52.         {
    53.             if (experience >= experienceRequired)
    54.                 RankUp();
    55.         }
    56.     }
    57.  
    58.  
     
  29. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    Did you hook up the script's OnDeath function to the AI's Death event?
     
  30. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    erm how do i do that ? sorry been a long day
     
  31. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    It sounds like you need to spend a little more time with the documentation to get a better grasp of the basics. However, to do this just go to the Emerald AI System script in the Inspector. Select AI's Settings and the Events button. There you will see all the possible events you can hook up. Select Combat and then go down to the Death() event. Click the + button to add a handler. Drag the AI from the hierarchy into the Object slot. Then select the No Function dropdown. Find the name of the script such as AIHelper and then select the function such as OnDeath.

    [EDIT]
    Looks like the docs don't really explain the Events system so sorry for sounding a bit harsh. I thought there was a video tutorial somewhere about it, though. I'll try to find it.
     
    Last edited: Oct 9, 2019
  32. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    ah yeah documents are abit lacking. Done this but when i add event in the inspecter emerald ai system my AI wont die . when i remove the event the ai can be killed any ideas?
     
  33. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    Something else must be wrong. Adding an event handler won't break anything unless your event handler code itself is messing the AI up. The event is only called when the AI dies and calling the event is only extra code beyond what EmeraldAI is doing. What does your script look like exactly?
     
  34. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    this is my xp the ai should give
    Code (CSharp):
    1.  
    2.         public int experienceOnDamaged;
    3.         public int experienceOnDeath;
    4.  
    5.         public void OnDamaged()
    6.         {
    7.             GetComponent<XPGiver>().experience += experienceOnDeath;
    8.          
    9.         }
    10.  
    11.         public void OnDeath()
    12.         {
    13.  
    14.             GetComponent<XPGiver>().experience += experienceOnDeath;
    15.  
    16.        
    17.         }
     
  35. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    First, you should reduce your script down to just the following:

    Code (CSharp):
    1.         public int experienceOnDeath;
    2.  
    3.  
    4.         public void OnDeath()
    5.         {
    6.  
    7.             GetComponent<XPGiver>().experience += experienceOnDeath;
    8.  
    9.      
    10.         }
    Since you only want to add XP when the AI dies. Aside from that, I don't see anything wrong with the way you are doing it. Can you take a screenshot of the Inspector window showing how the script is hooked up to the Death event? I can't imagine what could be wrong, but there is no way this code should prevent the AI from dying.

    [EDIT]
    Wait. I think what might be happening is that your GetComponent<XPGiver>() is probably returning null, which would cause the script and your AI to stop functioning properly. Is the XPGiver script on your AI or somewhere else? The way you wrote this assumes it is attached to the AI, which makes no sense to me. It should be a global instance of some sort so that you only need one XPGiver.
     
  36. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,066
    For Dialogue System users, the Dialogue System Extras page has a patch for the integration package to update it for Emerald AI 2.3.0.2.
     
    BHS likes this.
  37. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    screen shot of set up and console for a reference issue on script. Player has the xpgiver script and xphelper is for ai
     

    Attached Files:

  38. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    As I suspected. Please see my edited comment above for the null reference that I figured was happening.
     
  39. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    ah right xp helper is attached to the ai as want a variant depending on which ai my player kills?
     
  40. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    XPHelper, yes, but not XPGiver. Where is XPGiver located?
     
  41. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
    ah its cool done it thanks though you have helped alot :) anyway to make it though so depending on ai level depends on xp gained?
     
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,751
    You mean you want different XP amounts for different AI Level? If so, then I assume you are adjusting the AI level field as well as health amount in some dynamic way through code? As is, these fields are static and you would need multiple AI prefabs with different values. And if you have multiple prefabs with different AI level/health then you can just set their XP value differently.

    However, if you are intending to adjust level/health and other parameters dynamically through script then you can simply do the same for the XP values as well. So many different ways to handle this so it all depends on how you are structuring it.

    I'm actually working on creating a single prefab for an AI and dynamically changing the AI parameters after the AI is spawned from a pool. I will then also adjust their XP value based on some formula such as xpValue * level.
     
  43. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    299
  44. marco-maceratesi

    marco-maceratesi

    Joined:
    Sep 20, 2013
    Posts:
    9
    I apologize for the delay in the response.
    There are no colliders on weapons, the only thing I didn't mention is that Emerald AI character has the default ragdoll of unity for death (instead of animation...).
     
  45. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    872
    @BHS , ive been posting about my issue trying to get the same effect you have in you lightning strike video on discord and on here (Not sure where my message has gone) but could you provide the sample code you used to change you AI human into the werewolf on the video? I keep getting errors using instantiate and i thought there was api code within emerald/unistorm but i cant find it in the docs.
     
  46. CDVoss

    CDVoss

    Joined:
    Jun 24, 2019
    Posts:
    3
    Still does anyone else here on the forum, have the problem regarding the obstruction timer?
    Ive even tried it on an empty project on the default guardian AI from "Emerald AI". But the obstruction timer doesnt seem to work at all. Neither do the stationary option. The AI moves immediately after the player is out of the view.
    The obstruction timer is a little importnant to me, since i want some NPC´s to be less reactive than others, so they just dont swarm in on the player.
    Hope someone could look into.
    Best regards
    -CDVoss
     
  47. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    605
    I just got Emerald AI and so have a newby question.

    When setting up the AI In the scene... can I then drag the Animal Object into the Project window and then use that prefab in CRUX?

    Also do I need a navmesh for this to work, as CRUX spawns the animal without but Emerald AI seems to suggest I need to bake a navmash?

    Any advice appreciated, thanks.
     
  48. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    If you would like to play a custom animation, you can assign the animation to the AI's Emote Animations List and play it using the following code with Emote Animation ID:
    Code (CSharp):
    1. EmeraldAIEventsManager EventsManager = GetComponent<EmeraldAIEventsManager>();
    2. EventsManager.PlayEmoteAnimation(int EmoteAnimationID)
    The AI should stop and play the emote animation then continue to its destination.
     
  49. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    I'll take a look at this to make sure everything is working correctly. If not, I'll get it fixed.
     
  50. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,117
    The ragdoll shouldn't affect the AI's detection process as the ragdoll components are disabled on start. Can you try enabling the Debug Tools (located at the end of the Docs tab) to get a better idea of exactly is being detected and/or obstructed? This will allow Emerald AI to debug log the current target as well as any obstructions to the Unity Console.
     
unityunity