Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

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

  1. Al-

    Al-

    Joined:
    Jun 5, 2015
    Posts:
    25
    It's working now. Thanks!
     
  2. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,284
    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.
     
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,284
    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.
  4. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,284
    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
     
  5. BHS

    BHS

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

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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).
     
  7. zKici

    zKici

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  9. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  10. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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 :(
     
  11. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  12. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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 :)
     
  13. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
  14. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    yeah like exactly like that :)
     
  15. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    284
    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.
     
  16. magique

    magique

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

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  19. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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 ?
     
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  21. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    257
    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
     
  22. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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:

  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  24. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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:

  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  26. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  28. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
  29. burkenater14

    burkenater14

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

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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
  32. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

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

    unity_7UFP4-iCkwsgjg

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

    magique

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

    unity_7UFP4-iCkwsgjg

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

    magique

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

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    :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
     
  39. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  40. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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?
     
  42. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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.
     
  43. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    316
    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
  44. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    20
    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?
     
  45. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    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
     
  46. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    Sure. In any case you'd have to write custom code.
     
  48. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    @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.  
     
  49. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,835
    Right. Just set the playerAttackDistance to be closer than the aiAttackDistance and it should adjust automatically depending on the target.
     
unityunity