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

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    124
    Hey BHS! This one I'm working with Invector Melee with EAI 2.3

    - Tag and Layers correct on both EAI and Invector
    - Script Edits done for integration
    - Invector "Damage Layers" set
    - SendEmeraldDamage Events correct
    - Damage to EAI works, Damage to Invector Character does not.
    I have a different project on EAI 2.2 and cross checked settings - Working perfect.
    I may have missed something as always. :) Thoughts?
     
  2. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    how do make it so my ai only give xp when killed by the player ? my player at the moment gets xp when ai kill each other as well which i don't want?
     
  3. vanzie11

    vanzie11

    Joined:
    Apr 14, 2019
    Posts:
    3

    I am having the exact same issue, however after some testing I found that If I attack the AI first with a random number of hits, the AI eventually starts causing damage to the player. And another strange thing is that with different AI's, the results are also different...some AI's don't cause damage to the player at all. I really hope someone can assist us with a solution. :)
     
  4. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    I've tweaked to apply to my project is I want it to work only on one AI animal.

    Code (CSharp):
    1. void LightningStrikeEvent()
    2.     {
    3.         Debug.Log("Lightening hit something");
    4.         if (UniStormSystem.Instance.LightningStruckObject = this.gameObject)
    5.         {
    6.             Debug.Log("This wolf hit I will change to werewolf");
    7.             //Instantiate an new AI in the struck object's place
    8.             GameObject SpawnedAI = Instantiate(wereWolf, UniStormSystem.Instance.LightningStruckObject.transform.position, UniStormSystem.Instance.LightningStruckObject.transform.rotation);
    9.             GameObject SpawnFX = Instantiate(lightningParticleEffect, this.transform.position, Quaternion.identity) as GameObject;
    10.             //Destroy the struck AI
    11.             Destroy(UniStormSystem.Instance.LightningStruckObject);
    12.            
    13.             //Instantiate(wereWolf, wolfie.transform.position, Quaternion.identity);
    14.             //add soundfx for change, remove wolf to do clean and removelistner put sound fx on spawn event of werewolf. Also particle event and animation
    15.         }
    16.     }

    Thanks, is it decided by a random element as sometimes the animal appears to be hit as the flames particle effect plays but the lightining event does not?

    Did you also add the particle effect extra on the video as that doesn't play on my event. Finally you don't removelistner, is that ok with how you run emerald code?
     
  5. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Yes, baked NavMesh is required for AI to work correctly.
     
    Hawk0077 likes this.
  6. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    This is happening because you need to follow the upgrade guide from 2.2 to 2.3 if you have already done it: https://docs.google.com/document/d/1MD-0MwSQwbp8J3UtRIESXsPi66ltJFbetVF5PHAR-_U/edit

    If you have, you need to make sure the AI that has this error has its Animator Controller regenerated as covered in the upgrade guide above.
     
  7. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    That all seems correct. When I get the chance, I'll look into why this isn't working correctly.
     
  8. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Where your script gives the player XP, have an if statement that checks if the AI's current target is the player.
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    What may be happening with the fire is that the ground is being hit instead of the AI. Does your AI receive damage when this happens? The lightning event is only called if it's an object is hit that isn't the terrain, if I remember correctly.

    The particle effect was also instantiated and the lightning effect on the AI's mesh was done with enabling an already present particle effect with the AI's Skinned Mesh Renderer as the particle's Shape. After a few seconds, the effect is disabled.
     
    AndyNeoman likes this.
  10. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    bhs when i set target as player my player only gains xp from one killed ai how can i make it so it works on every ai? (have duplicated my ai)
     
  11. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    I'm wondering how to implement this:
    • I have 10 potential companion AI that the player can have on their team to assist them.
    • The player can only take 4 of them with them to each level, so 6 must stay behind.
    • The player will move to each scene in the game with trigger colliders.
    • The player is singleton, and persists through scene changes.
    • Currently, the companion AI do not collect anything, or carry any special weapons, so I can just instantiate them rather than make them persist from scene to scene. Their health is set to regenerate, so if they start each scene with 100 health, not a big deal (for now).
    • If the companion dies, I may set their bool to false making them unavailable.
    How would you implement this?

    At the moment, I have created 10 GameObjects, and a hasCompainon<name> bool for each companion.
    Using the example SpawnCompanion script as a base, I created a series of 10 ifs:
    Code (CSharp):
    1.        
    2.         void Spawn_Companions()
    3.         {
    4.             while (CurrentCompanions < TotalCompanions)
    5.             {
    6.                 if (CurrentCompanions < TotalAllowedCompanions)
    7.                 {
    8.                     if (hasCompanionAbby)
    9.                     {
    10.                         CompanionAIObject = CompanionAbby;
    11.                         TotalCompanions++;
    12.                     }
    13.                     if (hasCompanionJacob)
    14.                     {
    15.                         CompanionAIObject = CompanionJacob;
    16.                         TotalCompanions++;
    17.                     }
    18. .....
    19.  
    The idea is OnLevelLoaded to call the Spawn_Companions() function and instantiate the companions whose bools are true.
    VERY primitive. There must be a "better" way. Ideas? Something in EAI that handles this issue better?

    Mark
     
  12. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Hi, so I managed to get the navmesh baked and now the AI animals spawn with Crux. But with some issues.

    1: After setting up the animations as the tutorial video using info below.

    AI Layer: AIAnimal
    AI Tag: AIAnimal

    The AI doesnt attack the Player when I enter its radius. Is there something I need to add to the player? I noticed an invector tutorial which I will now watch as my player is an invector character.
    I just want animals to either run away or attack when the player is within its radius for now.

    I am working on a single animal in the scene (Boar) to see if I can get it to attack (like the tutorial) or run etc when the Player is in the radius of the animal but it doesn't so far.

    Any tips or tutorials welcome although I wil watch the invector integration now.

    Many thanks

    After following the Invector tutorial this works fine now thanks. FIXED
     
    Last edited: Oct 12, 2019
  13. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    My AI enables (and disables if not killled) objects via animation events, and this works great during combat. However, when killed, the objects are sometimes not disabled by the DisableAllItems Death Event. Any ideas why this could be?

    Also, is there any ETA for the On Stop Combat (or On Lose Target) events discussed a few months back?

    Thanks
     
  14. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    If i have to many ai on my screen then when my player kills them one by one sometimes they don't display the death and animation and carry on standing up (some carry on fighting) even though emerald ai system is disabled upon death and they are dead any ideas as to why this is happening?
     
  15. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Does this work with AI Pathfinding Pro?
     
  16. yarskiss

    yarskiss

    Joined:
    May 7, 2019
    Posts:
    5
    In my first project i got Ai to attack UFPS player and vice versa ok, but when I created another one nothing happens... AI attacks player only when shot at - and the settings seem be to the same. Only difference was that on the 2. project there were no Enemy / LocalPlayer layers - so I created them. Should these layers come from another asset that are not present on my second project?
     
    Last edited: Oct 14, 2019
  17. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Hello,

    I have an ability with an ability effect prefab - fire arrow

    In AI settings Combat Damage Settings Ranged,

    Ranged attack transform I added an empty prefab in the NPC where the fire arrow should spawn from.

    There is an offensive animation set and offensive ability the one with the fire arrow.

    However, even though the animation for casting this plays out, the fire arrow is never spawned,

    Am I missing something?
     
  18. Al-

    Al-

    Joined:
    Jun 5, 2015
    Posts:
    26
    Hi,

    Is there any function to remove the body of the AI after some seconds of delay since dead?
     
    Alex3333 and Hawk0077 like this.
  19. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    I don't think there is. I believe the Death Delay function just disables components.
    I put together a simple Destroy script. The script goes on the AI, and will be automatically found and disabled. It gets enabled on death.
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class RemoveOnDeath : MonoBehaviour
    7. {
    8.     public void OnEnable()
    9.     {
    10.         Destroy(gameObject, 10f); // This should be larger than Emerald's DeathDelay.
    11.  
    12.     }
    13. }
    14.  
    You will have to add a few things to EmeraldAISystem.cs. In the variables section add:
    private RemoveOnDeath remove;
    In the Awake function, add:
    remove = GetComponent<RemoveOnDeath>();
    remove.enabled = false;

    In the section that says "
    //The AI has died, initialize its death state.
    if (CurrentHealth <= 0 && !IsDead)"
    remove.enabled = true;

    Works for me, in fact I use a co-routine to slowly sink the bodies into the ground first so removal is less obvious.
    Your mileage may vary.
    Mark
     
    Al- likes this.
  20. Al-

    Al-

    Joined:
    Jun 5, 2015
    Posts:
    26
    Hi,

    Thank you!. I've tried that but I can't make it work for me
     
  21. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    This is a pretty basic script.
    Do you get errors?
     
  22. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi.

    Maybe this was already answered in this forum, but if I use this AI asset with multiplayer such as pun, how do I sync in between the movement and events?

    Obviously you only want to simulate real AI on the server side and not on client because that would cause a lots of problems, so my initial guess is to disable everything the ai does including nav agents, and then manually sync up transform and animator.. I guess transform sync is easy enough, but animator sync.. from brief look from the video, it looks like animator controllers are manually created per creation setting so... how do i find out about what parameters there and which ones are needed to be synced? In order to reduce the syncing as much as possible, normally not all parameters of animator needs to be synced.. but in order to do this, there must be some script helping with updating the parameters of the animator.. is there any helper scripts included in this asset?

    How do you guys handle multiplayer with this asset?
     
  23. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Is your Death Event on each of your AI? It should work with every AI that has the add xp event.
     
  24. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    bhs yes all the ai have the same xp event upon death but only some work
     
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You might want to put some Debug>Log statements in your code to see what's happening. Or, if you know how, attach to your Unity process debug using breakpoints.
     
  26. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    i just see the problem if the ai dosen't hit my player at all no xp is given not sure were i've gone wrong here is my code

    Code (CSharp):
    1.   public void OnDeath()
    2.         {
    3.                 RaycastHit hit;
    4.                 Vector3 forward = transform.TransformDirection(Vector3.forward);
    5.                 Vector3 origin = transform.position;
    6.  
    7.                 if (Physics.Raycast(origin, forward, out hit, 500f))
    8.                 {
    9.  
    10.                 if (GameObject.Find("Dino"))
    11.                 {
    12.                     hit.transform.gameObject.GetComponent<XPGiver>().experience += experienceOnDeath;
    13.  
    14.                 }
    15.  
    16.                 else
    17.                 if (hit.transform.gameObject.tag == "Player")
    18.                 {
    19.                     hit.transform.gameObject.GetComponent<XPGiver>().experience += experienceOnDeath;
    20.  
    21.                 }
    22.  
    23.             }
    24.             }
    25.          }
    26.  
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm not sure why you are using this raycast technique. It doesn't make sense to me. And the fact that you have an XPGiver on your AI is very odd as well. All you need to do is have a single component that adds XP, probably as part of a GameMaster singleton, and simply call a function such as AddXP(experienceOnDeath).
     
  28. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah right what technique instead of raycast ? collider hit?
     
  29. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    No, you don't need to do any kind of hit at all. Give me a minute and I will show you a simple code solution and maybe it'll make more sense.
     
  30. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
  31. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @unity_7UFP4-iCkwsgjg OK, so what you want to do is have some sort of GameMaster singleton that does all the major game control functionality. For this example, I'm just having it handle awarding XP, but in a real game you could have to handle other details such as activating/deactivating the player, playing battle music, keeping track of enemy targets, etc. So below is my simple GameMaster script:

    Code (CSharp):
    1. public class GameMaster : MonoBehaviour
    2. {
    3.     static GameMaster _instance;
    4.  
    5.     static public GameMaster Instance
    6.     {
    7.         get { return _instance; }
    8.     }
    9.  
    10.     private int _xp;
    11.  
    12.     private void Awake()
    13.     {
    14.         _instance = this;
    15.     }
    16.  
    17.     public void AddXP(int value)
    18.     {
    19.         _xp += value;
    20.         Debug.Log("XP is now " + _xp);
    21.     }
    22. }
    Add an empty game object to your scene and assign this script.

    Now, you need that AIHelper script that we talked about before. Here it is again:

    Code (CSharp):
    1. public class AIHelper : MonoBehaviour
    2. {
    3.     public int experienceOnDeath;
    4.  
    5.     public OnDeath()
    6.     {
    7.             GameMaster.Instance.AddXP(experienceOnDeath);
    8.     }
    9. }
    Attach this AIHelper to each of your AI units and be sure to hook the OnDeath function up the the Death() event as we explained before.

    That's it. Now all your AI when they die will award the specified amount of XP.
     
  32. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah brilliant i'll give it ago :) you have been fantastic help :)
     
    magique likes this.
  33. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    would i need a tag to ensure it gives xp only to player?
     
  34. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    If you need to distinguish deaths caused by player then you can always add some code into OnDeath to get the EmeraldAISystem component and check it's current target tag to make sure it's the Player. I don't have the AI system code in front of me, but something like the following:

    Code (CSharp):
    1. using EmeraldAI;
    2.  
    3. public class AIHelper : MonoBehaviour
    4. {
    5.     public int experienceOnDeath;
    6.  
    7.     public OnDeath()
    8.     {
    9.         var ai = GetComponent<EmeraldAISystem>();
    10.         if (ai && ai.currentTarget && ai.currentTarget.gameObject.tag == "Player")
    11.         {
    12.             GameMaster.Instance.AddXP(experienceOnDeath);
    13.         }
    14.     }
    15. }
    I don't remember if currentTarget is correct, but it's something like that. This is a quick and dirty example so it can probably be made better. But hopefully, you can proceed from there.
     
  35. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah right i only want ai to give xp when killed by player but at the moment if ai kill other ai my player gains xp. Anyways to stop this?
     
  36. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    The example I posted above should help resolve this, I believe.
     
  37. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah okies will test :)
     
  38. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    tried this but still no luck with xp, it damages my player but when i kill ai i don't get no xp
     
  39. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You must have missed a step.

    Did you attach the AIHelper to your AI and hook up the Death() event so it calls OnDeath?

    Can you verify that OnDeath is being called and getting to the AddXP function by putting some Debug.Log statements?
     
  40. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    followed steps its just not connecting to my gain xp script. Heres player script to gain xp not sure if i'm missing anything?

    Code (CSharp):
    1. public float experience;
    2.         public int maxXP;
    3.  
    4.         public float expBarLenght;
    5.  
    6.         public float sec = 20f;
    7.  
    8.    
    9.         private void Update()
    10.         {
    11.  
    12.  
    13.             if (experience >= maxXP)
    14.             {
    15.                 level++;
    16.                 maxXP += (50 * level);
    17.  
    18.  
    19.  
    20.                 if (level >= 0 != level <= 1)
    21.                 {
    22.                     GetComponent<EmeraldAIPlayerHealth>().maxHealth++;
    23.                     GetComponent<EmeraldAIPlayerHealth>().maxHealth += 5;
    24.  
    25.                 }
     
  41. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hi!
    I am encountering a serius issue and I hope someone can help me.
    I am moving the AI with Destination and changing it via script.
    When I use the StopMovement function the AI keep proceeding straight, ignoring the command.

    Can you give me a suggestion? I am getting crazy!

    Thanks :)
     
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Well, first off you shouldn't be performing an experience check in an Update loop. That code doesn't need to execute unless experience has changed, which would happen only when you call an AddXP function of some sort.

    Second, I have no idea what your logic is supposed to be in the following code:
    Code (CSharp):
    1. if (level >= 0 != level <= 1)
    I don't think that's any valid logic and doubt it will do what you expect. And even if it did manage to get inside the if clause, you are then incrementing max health by 1 and then incrementing it again by 5 right after that.

    All that being said, none of that code above actually updates the XP. I'm not sure where you are getting stuck based on that.
     
  43. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    the level allows my player to level up i have that working fine when it gains xp( when i was doing the raycast it worked and i gained xp) how would i add to allow this code to update xp?
     
  44. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    We seem to be having a communication gap. If the code to level up the player works, then why did you show me that code? I thought the AddXP was no longer working. If that's true, then you simply need to verify you followed all the steps correctly. You can verify whether or not your OnDeath is being called by adding some Debug.Log statements to it. And you can Add Debug.Log to the GameMaster AddXP script to see if that is being executed as well. As far as leveling up, though, you should move that code into your AddXP function so it only executes when XP is actually added to the player.
     
  45. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    sorry didn't mean to copy that bit :(
     
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I just tried this and it works for me. Is it possible you are setting the destination again after calling StopMovement?
     
  47. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    @ magique i did it finally :) needed to get rid of that last script i placed :)
     
    magique likes this.
  48. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Followed the Ability and other documents on your drive

    I have an ability with an ability effect prefab - fire arrow

    In AI settings Combat Damage Settings Ranged,

    Ranged attack transform I added an empty prefab in the NPC where the fire arrow should spawn from.

    There is an offensive animation set and offensive ability the one with the fire arrow.

    However, even though the animation for casting this plays out, the fire arrow is never spawned,

    Am I missing something?
     
  49. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    Does emerald ai only allow the player to cause damage with raycasting?
     
  50. Al-

    Al-

    Joined:
    Jun 5, 2015
    Posts:
    26
    It's working now. Thanks!