Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. 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. LaCorbiere

    LaCorbiere

    Joined:
    Nov 11, 2018
    Posts:
    26
    That's spot on thank you very much. :)
     
  2. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,122
    Any update yet about location damage using ragdoll colliders? And also hit effect by raycast ? so where ever you aim theres blood.... @BHS
     
  3. THE_SUPREME_18

    THE_SUPREME_18

    Joined:
    Jan 12, 2020
    Posts:
    9
    Hey, I bought emerald AI, but I wanted to ask, how do I damage the AI from the player, and how do I damage the player from the AI? Which methods to call from the scripts to damage the AI and the player?
     
  4. adamofeden

    adamofeden

    Joined:
    Sep 19, 2020
    Posts:
    3
    Hey I see you were working on a game with stealth mechanics and I was wondering if you are able to set up a way for your player to escape from your AI after the AI has spotted your player. I am having trouble with the AI knowing the exact location of the player after the AI detects them.
     
  5. noahx

    noahx

    Joined:
    Nov 22, 2010
    Posts:
    56
    Hi. Are there any "generic" guides to Integrate Emerald AI with other systems/controllers? I'm currently using a custom Player Controller but I don't have an idea where/how to start to integrate Emerald AI. Thanks.
     
  6. williamian

    williamian

    Joined:
    Dec 31, 2012
    Posts:
    119
    ?, can the player use the abilities?
     
  7. XVB75

    XVB75

    Joined:
    Sep 12, 2020
    Posts:
    11
    Yes, exactly. How do you get them to fly away? Just move them on a trajectory away from the player and animate?

    Still a complete flying character that can land, walk and fly away would be a highly requested feature.
     
  8. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    297
    I have not been able to work that out yet, sorry. I figure that you'd need to track how long the player has been out of the AI Line of Sight, and if it has exceeded a certain amount of time, then call the method to clear the target and resume wandering/waypoints or whatever the AI's normal behaviour is.
     
    adamofeden likes this.
  9. SeymourGutz

    SeymourGutz

    Joined:
    Aug 9, 2019
    Posts:
    12
    Regarding flying while limited to navmesh, could a workaround trick be an option to dynamically adjust an agent's base offset to the target's hit transform? So if the player/target climbs on top of an obstacle, the flying enemy rises and can still see/attack. Not perfect for all cases, but better than nothing.
     
  10. Vera987

    Vera987

    Joined:
    Nov 15, 2016
    Posts:
    1
    Hello! Thank you for the Emerald AI, it seems very promising for our project! I have one question, I'm sorry if this has been answered before or if it's obvious, but is there an easy way to temporarily disable the AI? Our goal is to have a timeline run whenever attack is successful, during which only the timeline controls the enemy movement and animation. Thank you in advance!
     
  11. adamofeden

    adamofeden

    Joined:
    Sep 19, 2020
    Posts:
    3
    I see, thank you.
     
  12. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    741
    I use the official integration with Invector Shooter, but it is not flexible, so I am about to replace it with Stats Cog which will handle all my stats, attack, damage, etc. and damage dealers and hit boxes. I let Emerald handle the ai (come at me and attack), but Stats Cog will take over the battle math. BHS may have a better suggestion for you, but I am going this way. Good luck.
     
  13. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    It is, but you will need to add a line of code to the EmeraldAISystem script.

    Within this if statement:

    Code (CSharp):
    1. if (WaypointTypeRef != WaypointType.Random && WaypointsList.Count > 1 && !WaypointReverseActive)
    Find the following line within the EmeraldAISystem script:

    Code (CSharp):
    1. WaypointIndex = 0;
    And add the following code underneath it:

    Code (CSharp):
    1. ReachedDestinationEvent.Invoke();
    This will allow the ReachedDestinationEvent to be triggered when the AI reaches the end of its waypoint.

    Next, add this script to your AI. It will allow it to trigger an emote animation according to the EmoteAnimationID variable you set.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using EmeraldAI;
    5.  
    6. public class EmoteAnimationWaypoints : MonoBehaviour
    7. {
    8.     public int EmoteAnimationID = 0;
    9.     EmeraldAISystem EmeraldComponent;
    10.     int m_LastWaypoint = 0;
    11.  
    12.     void Start()
    13.     {
    14.         EmeraldComponent = GetComponent<EmeraldAISystem>();
    15.         EmeraldComponent.ReachedDestinationEvent.AddListener(() => PlayEmoteAnimation()); //Create a ReachedDestinationEvent
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         //First Waypoint Reached
    21.         if (EmeraldComponent.WaypointIndex == 1 && m_LastWaypoint != EmeraldComponent.WaypointIndex)
    22.         {
    23.             PlayEmoteAnimation();
    24.         }
    25.     }
    26.  
    27.     void ResumeMovement ()
    28.     {
    29.         EmeraldComponent.EmeraldEventsManagerComponent.ResumeMovement();
    30.     }
    31.  
    32.     void PlayEmoteAnimation ()
    33.     {
    34.         m_LastWaypoint = EmeraldComponent.WaypointIndex;
    35.         EmeraldComponent.EmeraldEventsManagerComponent.PlayEmoteAnimation(EmoteAnimationID); //Play an emote animation according to the animation ID
    36.         EmeraldComponent.EmeraldEventsManagerComponent.StopMovement(); //Stop the AI from moving
    37.         Invoke("ResumeMovement", EmeraldComponent.EmoteAnimationList[EmoteAnimationID].EmoteAnimationClip.length); //Resume movement after the length of the animation clip has been met
    38.     }
    39. }
     
  14. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    This may have to do with the NavMesh trying to function while the AI is underground. If the AI is not near the NavMesh, it can cause problems. One solution could be to disable the NavMeshAgent component while your AI is spawning then enable it when the spawning animation has finished.

    This can be done with a reference to your Emerald AI System and using the following code:

    Disable
    Code (CSharp):
    1. m_NavMeshAgent.enabled = false;
    Enable
    Code (CSharp):
    1. m_NavMeshAgent.enabled = true;
     
  15. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    Since Emerald AI is not a character controller, I have no plans to implement it with the new input system, unless things are not working correctly. You could try using Emote animations for transition animations or add in extra states for the transition animations on your dragon's animator controller.
     
  16. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    A NavMesh Obstacle is all you need to make your AI not run through the car. Make sure you set "Carve" to true so it will affect the generated NavMesh within your scene.

    NavMesh Obstacle
    https://docs.unity3d.com/Manual/class-NavMeshObstacle.html
     
  17. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    I never removed the cap from AI playing an emote animation while in combat. You should be able to remove this by opening the EmeraldAIEventsManager script and finding the line below and removing the if statement that checks the combat state.

    Code (CSharp):
    1. if (EmeraldComponent.CombatStateRef == EmeraldAISystem.CombatState.NotActive)
     
  18. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    The AI's collider is disabled on death to avoid interference with the AI's ragdoll and other functionality. When an AI is respawned or reactivated, this is re-enabled and properly set to the AI's current position. The Box Collider does not follow the motion of the ragdoll or its animations since it is not attached to any of the bone transforms of your AI.
     
  19. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    I haven't had any issues with Unity 2020. I will have to look into this though.

    Emerald AI's head look feature uses Unity's Inverse Kinematics. This requires your model to have the Humanoid Animation Type to work.
     
    LaCorbiere likes this.
  20. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,037
    Is the new patch ready?!
     
  21. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    I'm currently working on the location based damage update. Proper colliders on the AI and its body will be required if you want to have accurate blood where your bullets hit as a collider is needed for a raycast hit point. This will be possible once the location based damage update is released.
     
    mattis89 likes this.
  22. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
  23. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    The Emerald AI wiki covers everything, but there's no generic guide for setting up a custom character controller. I can add one when I get the chance.

    Basically, you just need to do the following:

    Where your player can damage targets, you need to check if the target is an Emerald AI agent, if it is, you can damage them as explained here: https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Emerald-AI-API#damaging-an-ai

    For your player to receive damage, you will need to open up the EmeraldAIPlayerDamage script and add your own function to damage your player and call it within the SendPlayerDamage function of this script. There are parameters that should give you everything you need. The amount of damage received, whether it was a critical hit, and the target that hit the player are all passed. There are examples within this script that call other 3rd party character controllers so you can get an idea of how it's done.

    Ensure that your player's tags and layers are properly setup with Emerald AI and that there are no colliders blocking the AI's line of sight. If your AI can follow the player, but does not attack, this is an indicator that there is an obstruction between the AI and the player. You can find the obstruction by enabling the Emerald AI Debugging Tools: https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Enabling-an-AI's-Debug-Tools
     
  24. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    Players cannot use the abilities by default, but you can code your own solution to do this. The Ability Objects are just scriptable objects that hold all of the data to be used when a projectile/ability is fired.
     
  25. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    Disable what specifically, the AI's movement?

    This can be done with the stopping and resuming movement API:

    Stop movement
    https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Emerald-AI-API#stopmovement

    Resume movement
    https://github.com/Black-Horizon-Studios/Emerald-AI/wiki/Emerald-AI-API#resumemovement
     
  26. LaCorbiere

    LaCorbiere

    Joined:
    Nov 11, 2018
    Posts:
    26
    Hi everyone. I'm messing around with a melee based combat prototype in VR. want to implement player sword blocking that can initiate a stagger animation on the Emerald Enemy. So when the enemy starts it's attack animation (in this case a sword swing), the player has a chance to intercept and block the enemy sword strike with the 'PlayerWeapon' before the emerald damage event is triggered. I'm using a 'OnTriggerEnter' script on the enemy sword that checks for the tag of the player sword and references the enemy Animator to play a stagger animation via the Animator on the Emerald AI. Problem is, I'm just not getting anything from the script. Have added a debug.log check to see if a connection is being recognised and nothing is written to the console. Enemy sword has a trigger collider. Tried the script below (minus the animator references) on a basic cube with a collider set as trigger and works fine. Any suggestions gratefully received. Unity 2020. Many thanks.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SwordBlock : MonoBehaviour
    6. {
    7.  
    8.  
    9.     [SerializeField]
    10.     private Animator enemyAnimator;
    11.  
    12.  
    13.     void OnTriggerEnter(Collider other)
    14.     {
    15.  
    16.         if (other.tag == "PlayerWeapon")
    17.         {
    18.             Debug.Log("Connection!");
    19.             enemyAnimator.SetBool("swordBlock", true);
    20.  
    21.         }
    22.  
    23.  
    24.     }
    25.  
    26. }
     
    Last edited: Feb 4, 2021
  27. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    245
    Gonna try here, because the discord channel is just useless.


    Q: Anyone know why my AI walks through the terrain, example at the foot of a hill, the ai walks stright "through" the hill.
    He does not fall, just walks straigt out through the terrain.
    He has RB, box collider, nav mesh agent and is working normally.
    have generated a navmesh on the terrain.. And he is set to Nav mesh navigation.

    It's as if, hes ignoring gravity, colliders and the terrain..
    also if he walks downhill, he never goes downwards, he just walks straight into the air :p

    Any ideas what i could check ?

    I have noticed the Nav Mesh Agent, walks of on it's own, without the character upload_2021-2-4_17-21-33.png :p
     
    Last edited: Feb 4, 2021
  28. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    460
    I would start with a check of the navmesh. It may need to be regenerated.
    Also, your navmesh agent (the green cylinder) is not placed properly on your character.
     
  29. Ben2390

    Ben2390

    Joined:
    Sep 6, 2014
    Posts:
    8
    I've not been using Emerald AI for long (after parking my own AI solution) but I'm pleased with the results!
    Feel free to check out my implementation of Emerald AI (with a couple tweaks) on the below link.

     
  30. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,122
    Awesome
     
  31. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    Hello
    My second question is, Why Chase distance cant be the same as detection distance? I would like to have enemy that just protect something and don't go away from its detection distance. Also why wander radius is also connected to Detect Range? I dont get why this limitations are here

    Another question is If We can in any way check if AI reached its destination by API?

    and last question, How we could disable whole AI with animator and navmesh, (disable / enable for optimization purpose) Is there any API, or we need ot disable AI component and animator and navmesh seprateley if Yes, what is best practice and in what order we should disable/ enable it to wont make any null reference or problems with AI ?
     
    Last edited: Feb 13, 2021
  32. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    211
    I'm trying out the Emerald AI Needs System with my AI. From what I can tell the AI will generate the waypoints to the "resource" then go back to wandering. I noticed that if I remove that "resource" from the scene the AI will continue to go back to that "resource" even though it's gone. Is there are way to remove the waypoint or something?
     
  33. gtox

    gtox

    Joined:
    Apr 23, 2013
    Posts:
    15
    Is it possible to create a damage over time effect, without using a projectile? For example if you have a venomous animal that bites or stings.
     
  34. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    245
    Been using EAI for so many different things.. Now i am wondering can i use EAI as a "NPC populator"
    IE: Make the AI walk around dynamically.. YES. but how about using the navmesh and "STICK" to specifc layers.

    I imagine creating layers in a city, Sidewalk = lowcost, crossing = medium cost, Road = high cost.
    So they randomly walk around, sticking primarily to the sidewalk..

    Update, this is working just fine.
    I was using Crux to spawn in NPC's, the only problem is Crux is terrible at spawning in anything, even with distance set to minimum and spawnrate to max, and chance to 100% there is def, not enough spawns.

    So i will look for something else than Crux that handle the spawning and pooling around the player.
     
    Last edited: Feb 15, 2021
    dsilverthorn likes this.
  35. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    @BHS still waiting for reply
     
  36. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    It looks like you have ragdoll components that are still enabled while the AI is alive, which shouldn't be possible. Are you getting any errors?

    Also, you need to rebake your NavMesh. Anytime you make changes to your terrain, you will need to do this. NavMesh is explained more here: https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html
     
  37. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    If the chase and detection distances are equal, the AI will constantly be fighting between detecting the player and the player being too far away which results in them bouncing back and forth between each action.

    You can see if an AI has reached its destination with an OnReachedDestinationEvent as explained here: https://github.com/Black-Horizon-St...ald-AI-Unity-Events#onreacheddestinationevent

    You can also use the bool from EmeraldComponent.AIReachedDestination to see when an AI has reached its destination.

    Emerald AI automatically disables an AI's Animator and most of the system when an AI's renderer is culled or not visible with the camera, when using the Disable when Off-Screen feature. You can set this up with each AI by going to AI's Settings>Optimize and enabling Disable when Off-Screen. Ensure that you set the AI's renderer/renderers.
     
  38. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    The AI shouldn't be able to go back to the resource location as they are cleared each time the AI returns to wandering. Once they look for new resources, they regenerate completely new waypoints. The only way an AI could still generate a waypoint to a resource is if a collider is still present where the resource was as it looks for colliders of the appropriate layer when generating resource waypoints. If you want to add this mechanic, you simply need to disable the collider of the resource object when it's depleted.
     
  39. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,372
    No, but you can add this mechanic by creating a custom script with a coroutine that is triggered when the AI damages its target and continuously damages the target every damage increment.

    Use this script as a starting point. Attach it to an AI you would like to damage. Pressing the spacebar key will damage an AI over time. You can easily alter it to have it damage a specific AI triggered with a certain ability.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using EmeraldAI;
    5.  
    6. public class DoT : MonoBehaviour
    7. {
    8.     EmeraldAISystem EmeraldComponent;
    9.     Coroutine DoTCoroutine;
    10.  
    11.     private void Start()
    12.     {
    13.         EmeraldComponent = GetComponent<EmeraldAISystem>();
    14.     }
    15.  
    16.     /// <summary>
    17.     /// Damages a target over time.
    18.     /// </summary>
    19.     /// <param name="DamageAmount">The amount of damage delt each damage increment.</param>
    20.     /// <param name="DamageIncrement">How often the damage amount will occure witin 1 second.</param>
    21.     /// <param name="Length">How many seconds the damage over time will last.</param>
    22.     /// <param name="Stacks">Can the damage over time be stacked?</param>
    23.     public void DamageOverTime (int DamageAmount, int DamageIncrement, float Length, bool Stacks)
    24.     {
    25.         if (!Stacks)
    26.         {
    27.             if (DoTCoroutine != null) { StopCoroutine(DoTCoroutine); }
    28.             DoTCoroutine = StartCoroutine(DamageOverTimeInternal(DamageAmount, DamageIncrement, Length));
    29.         }
    30.         else if (Stacks)
    31.         {
    32.             DoTCoroutine = StartCoroutine(DamageOverTimeInternal(DamageAmount, DamageIncrement, Length));
    33.         }
    34.     }
    35.  
    36.     private void Update()
    37.     {
    38.         if (Input.GetKeyDown(KeyCode.Space))
    39.         {
    40.             //Damage a target for 5 points of damage, every second, for 5 seconds
    41.             DamageOverTime(5, 1, 5, false);
    42.         }
    43.     }
    44.  
    45.     IEnumerator DamageOverTimeInternal (int DamageAmount, int DamageIncrement, float Length)
    46.     {
    47.         float lnegthTimer = 0;
    48.         float incrementTimer = 0;
    49.  
    50.         while (lnegthTimer < Length)
    51.         {
    52.             lnegthTimer += Time.deltaTime;
    53.             incrementTimer += Time.deltaTime;
    54.  
    55.             if (incrementTimer >= DamageIncrement - 0.1f)
    56.             {
    57.                 EmeraldComponent.Damage(DamageAmount);
    58.                 incrementTimer = 0;
    59.             }
    60.  
    61.             yield return null;
    62.         }
    63.     }
    64. }
     

    Attached Files:

    • DoT.cs
      File size:
      2 KB
      Views:
      3
  40. Bioman75

    Bioman75

    Joined:
    Oct 31, 2014
    Posts:
    59
    How do I check if the emote is finished? Also any ETA on the Damage areas update?

    Edit: I found the problem its because its an emote if I set it to the idle animation it'll correctly play the digging out of ground animation and then stay where it originally dug up. My problem is that the ai after spawning teleports underground does the digging out animation and then teleports back onto the nav mesh. I didn't want it teleport the ai to the nav mesh after completing the animation. So my question is why does the emote do that and how can I make sure it doesn't do that?
     
    Last edited: Feb 18, 2021
    SickaGamer likes this.
  41. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,037
    Also can we get more native Flying AI?
     
  42. sanya_kotov

    sanya_kotov

    Joined:
    Feb 17, 2015
    Posts:
    4
    Check that your gameObject have rigidbody component - on trigger enter not working without it
     
  43. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    Thanks for info but still dont understand Why Wander Radius cant be the same like detection range, I dont see here any corelation, But even if IT has to be why not for example 0.2 m difference not 2-3 meters, What really limits system usage.

    What about optimization I know about it but This is not our use case. We just want to disable AI because We use it only in some area no matter if someone looking in that direction or not we wont disable ai in some situation, How we could do it then? Just disable renderer? This is the same as culled?
     
  44. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    @BHS Also I see that even send when destination reached, very often is send When AI is far away from destination point I have exactly the same AI duplicated, and some of them have sent that event when they are in the middle of the road. Could You help with that? I see the3re was some release notes about fixing problem but it seems like it is still here
     
    Last edited: Feb 22, 2021
  45. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    @BHS is there a chance for a faster reply?

    Also We are fighting with that null reference, probably because we disable some emerald AI dectection, for optimization on our own, We dont want to use builded one, Maybe There should be some api to Turn on optimization, disable, to be able to do it manually, Could You let me know what is related that null reference?
     
    Last edited: Feb 24, 2021
  46. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
  47. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,037
    @BHS RFPS is back!
     
  48. bsimser

    bsimser

    Joined:
    Sep 8, 2014
    Posts:
    57
    Looked through the documentation (it really needs a better platform where you can search) and tutorial videos. I can't see any options where you have one-handed and two-handed animations for an AI? I have a lot of monsters that have both and not sure there's a way to set them up with Emerald is there?
     
  49. Ntotor

    Ntotor

    Joined:
    Jun 21, 2020
    Posts:
    1
    Hi I've got two questions about this product,

    I've looked the documentation about needs : as I understand it I could set just one need, is it correct ? (I was thinking of drinking, eating and sleeping for a wildlife).

    Another question : I've already set script and mechanism for my IA for different task like mining, building etc ... But I wish to delegate all the fighting parts to Emerald, as I see I can switch off/on the Emerald AI via script but how to manage the Mechanism part to keep my already done and use those created by Emerald ?

    Sorry if already asked, it could be fine to have an mcq in the documentation :)

    Thanks to all replies
     
  50. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    466
    @BHS Still waiting for any reply from You, Reached Destination Event problem block some part of our work. (Tried on e-mail, here and on discord, over 10 days without reply now.)
     
    Last edited: Mar 2, 2021 at 5:39 PM
unityunity