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
    That looks about how I would go about it, but instead of using Instantiate, I would initially spawn all AI with:
    Code (CSharp):
    1. EmeraldAIObjectPool.Spawn(GameObject, Transform, Quaternion);
    Then disable all of them when going to the next scene and re-enable them as needed. AI are automatically reset when disabled and re-enabled. I hope this helps.
     
  2. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Sometimes the transition time from one animation to the next interfere with the Animation Events (this is a known Unity bug). What you can do to make sure Animation Events are being called consistently, is make sure they are not in the transition range of the animation. This can be seen by viewing the AI's animation transitions to the Death state.

    I'll try to get the stop combat event added with the next update.
     
    Deckard_89 likes this.
  3. BHS

    BHS

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

    I haven't had the chance to look into multiplayer support, but I plan on it soon. Another user was able to add support by following these steps which they provided. It's for UNET, but I'm sure the process will be similar: https://forum.unity.com/threads/rel...ality-ai-solution.336521/page-76#post-4920905
     
  4. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Not currently. Emerald AI uses Unity's NavMesh. However, I do plan on looking into other options, such as A* Pathfinding Pro, soon.
     
  5. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    i've asked this question already a while ago when i first started using emerald but i can't for the life of me find the question and answers to it. How can i stop my ai colliding into each other when attacking each other ? ( both ai have colliders attached with istrigger checked).
     
  6. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    @BHS not sure if my posts are invisible
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You mean you don't want them to be able to walk through each other?

    If so, I think there are two possible approaches. I haven't tried either of these so these are just unproven ideas.

    One would be to add a child collider to each AI and set them to a Layer that only collides with the same layer. For example, create a new Layer called AICollider and make sure in your Physics matrix that AICollider layer only collides with AICollider layer.

    Another would be to attach NaMeshObstacle to each AI. This might prevent them from being able to navigate into the other AI's space. I would prefer this approach myself if it works.
     
  8. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Nope, not invisible. Maybe he just missed it or hasn't gotten to it yet. I would help you myself, but I haven't yet tried the feature you are using yet so have no knowledge on it.
     
  9. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah adding extra colliders don't seem to enable when i press play :( they seem to just keep running when they are meant to attack so not even attacking or causing each other damage :( not sure why ? i'll test the NavMesh0bstacle see if that makes a difference :) trying to get two cows to butt heads had it working before the update but now its not :(
     
  10. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Are they extra colliders on the root of the AI or a child game object? I can try this out myself in a little bit and see if I can get either working.
     
  11. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    add the navobstable and they just run around in circles crazy lol . I have a box collider on the top of the head covering whole of head and face :)
     
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Oh, now I recall that the system disables extra colliders even if you add them. So that's a no go.

    So, let me try to understand what you want exactly. You are trying to get 2 AI to collide with each other, but not go through each other? So that you can have 2 rams butt heads? I was just thinking you wanted them to avoid contact. But you want them to contact each other, but then have some sort of reaction when they do?
     
    unity_7UFP4-iCkwsgjg likes this.
  13. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    yeah like exactly like that :)
     
  14. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    Yeah, Emerald automatically disables extra colliders when play begins. It's going to be altered in a future version, also the option to receive damage via separate colliders will be added.
     
  15. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, I think I have a possible solution. I'll try it out and let you know.
     
  16. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, so the first part is to get around the issue with EmeraldAI disabling our extra colliders. Attach the following script to your AI with the head colliders and add those colliders into the Colliders list for this script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EnableColliders : MonoBehaviour
    6. {
    7.  
    8.     [SerializeField]
    9.     private List<Collider> _colliders = new List<Collider>();
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         StartCoroutine(DelayedEnableColliders());
    15.     }
    16.  
    17.     IEnumerator DelayedEnableColliders()
    18.     {
    19.         yield return null;
    20.  
    21.         for (int i = 0; i < _colliders.Count; ++i)
    22.         {
    23.             _colliders[i].enabled = true;
    24.         } // for i
    25.     }
    26. }
    This waits one frame and then enables any colliders you have put in the list. So they will be functional again after EmeraldAI disables them.

    This might be all you need. However, to allow some sort of reaction when the colliders hit, I will post another script shortly. If you already have that part then you won't need it.
     
  18. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah cool thank you i don't have the reactions only what emerald al provides but my cows don't seem to damage each other either ( followed the steps tags and factions are set up ) not sure whats going on ?
     
  19. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You mean when they butt heads there is no damage? Yeah, that would be expected since that is something extra we are adding on top of the AI itself. Emerald doesn't have any concept of collision damage.

    Are they colliding though at least? If so, I will get you the next part shortly.
     
  20. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Well, perhaps. Its just that I've seen responses to posts after mine (and this is the 2nd time me reposting it)

    Thats all,

    Thanks
     
  21. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah right but before the update they were able to kill each other. Unfortunately not they are way to close to display attack animation :( here is a screenshot :)
     

    Attached Files:

  22. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Is the butting heads animation an attack in EmeraldAI? If so then that should cause damage of some sort when they hit. Change the head colliders to the same layer as the root AI and make the colliders triggers. That might fix it.
     
  23. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    added a better view basically the attack is like a stomp then low head and then raise and nope still getting this issue (screenshot)
     

    Attached Files:

  24. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Make head colliders same layer as Root AI and don't make them triggers. I notice that the main AI collider isn't a trigger either so it's worth a try. I don't really have an equivalent AI with that sort of attack so it's hard to test.
     
  25. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    tried didn't work :( they still go through each other
     
  26. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Yeah, I'm analyzing it now and the reason is because Emerald changes the Rigidbody of the AI to Kinematic and this prevents any child colliders from getting OnCollisionEnter events. So, the system is working against us here. I'm trying to figure out a way around it.
     
  27. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
  28. burkenater14

    burkenater14

    Joined:
    Sep 4, 2019
    Posts:
    2
    This Can be done
     
  29. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Try this. Use this modified script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EnableColliders : MonoBehaviour
    6. {
    7.  
    8.     [SerializeField]
    9.     private List<Collider> _colliders = new List<Collider>();
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         StartCoroutine(DelayedEnableColliders());
    15.     }
    16.  
    17.     IEnumerator DelayedEnableColliders()
    18.     {
    19.         yield return null;
    20.  
    21.         GetComponent<Rigidbody>().isKinematic = false;
    22.         for (int i = 0; i < _colliders.Count; ++i)
    23.         {
    24.             _colliders[i].enabled = true;
    25.         } // for i
    26.     }
    27. }
    28.  
    Also, change the RigidBody on each AI so that all rotations are frozen and position is frozen. See if it is able to trigger the damage on the attack now.

    Note: I don't know what side effects might come from changing RigidBody to non-kinematic. Although it seems to be working fine from my limited testing.

    [EDIT]
    In this new test, make sure the head colliders are not triggers. And put them on their own Layer so they only collide with each other as before.
     
    Last edited: Oct 21, 2019
  31. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah working much better thank you but they don't perform their attack animation where they lower their head any ideas? :)
     
  32. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Were they performing the animation before adding this new script and colliders?
     
  33. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    yeah :( they perform the action when attacking the player just not the ai
     
  34. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    To be clear, they also performed the action when attacking AI before adding the new script and colliders?
     
  35. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    yeah :/ i mean they still weren't damaging but they did the attack animation
     
  36. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Just for sanity check, disable the EnableColliders script by unchecking it in the inspector. And let me know if it's animating again.
     
  37. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    :O ah no it's not doing the animation now just running into each and carrying on running could it possible be a distance issue? ah wait it is took a while they were to close. But still not working when i enable that script
     
  38. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, so disabling the script would be the equivalent of going back to the way you had it before. So, it isn't using attack animation against AI in either case. So, definitely another issue.

    When you say still not working with the script do you mean no animation or no damage? I thought you had gotten the damage part to work with script.
     
  39. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    no animation or damage towards ai only against player. Last time i checked they ai did damage was before the update until today :(
     
  40. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    okay got it playing the animation had to further the distance but now it attacks the player from distance :( any ideas to allow for both further distance for butting heads and close up attack for player?
     
  41. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    So, they butt heads now and do damage? But attacks on player are at distance? I'm sorry, but just unclear what's working or not working at this point.
     
  42. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah sorry i'll try explain it better :)

    My Ai butt heads after now display the attack animation (had to increase attack distance) just checked damage now and ai can damage ai :)

    Because i had to increase attack distance to allow my ai to butt heads and display their attack animation my ai now attack the player from a distance causing damage (want the ai to get close to the player to attack and cause damage)
     
    Last edited: Oct 17, 2019
  43. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    31
    Hello again, I set up a new AI agent but decided to scale it down to 75 percent after I set her up. I am getting an issue with the agent sliding around the floor now when moving. If I recall correctly ; last time I had this issue you said it was my nav mesh agent size not matching up with the settings in the EM AI script which worked for that case but not for my current project.

    Could this be happening because of the scaled down agent gameobject? Should I just always scale my character objects before I set up the AI?
     
  44. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Sounds like you need some way to dynamically change attack distance based on whether the AI are attacking a player or the AI are attacking each other. I don't have time at the moment to code something up, but you should be able to add some sort of listener to your AI that checks if it has a target and whether the target is a player or another AI and then modify the attack distance based on that. That's something that could go into your already existing AIHelper script or whatever you are calling it.

    [EDIT]
    This is the sort of thing that I think Playmaker would be good for
     
  45. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    would it be possible to use tag detection?
     
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Sure. In any case you'd have to write custom code.
     
  47. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @unity_7UFP4-iCkwsgjg OK, so here is an example of changing the attack distance using tag to identify as player. This Update code can be placed as part of your AIHelper script that is attached to your AI. Also, note that instead of grabbing the EmeraldAISystem component each time, you could do this once in the Awake() function. You can also change this to only run every so many frames instead. This is just a quick and dirty example.

    Code (CSharp):
    1.         public float playerAttackDistance;
    2.         public float aiAttackDistance;
    3.  
    4.         public void Update()
    5.         {
    6.             var aiUnit = GetComponent<EmeraldAISystem>();
    7.             if (aiUnit.CurrentTarget != null)
    8.             {
    9.                 if (aiUnit.CurrentTarget.tag == "Player")
    10.                 {
    11.                     aiUnit.AttackDistance = playerAttackDistance;
    12.                 }
    13.                 else
    14.                 {
    15.                     aiUnit.AttackDistance = aiAttackDistance;
    16.                 }
    17.             }
    18.         }
    19.  
     
  48. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah okies so it would allow my cow to move close to the player?
     
  49. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Right. Just set the playerAttackDistance to be closer than the aiAttackDistance and it should adjust automatically depending on the target.
     
  50. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah still no such luck it still doesn't get close enough it stays at a small distance away
     

    Attached Files: