Search Unity

[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. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    A video perhaps ? it's faster and easy to make.

    A script doing interface (damage function and faction) will allow Emerald to recognize any other objects, even objects using another AI system like Behaviour Designer.
     
    Last edited: Mar 30, 2018
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @BHS When you say that you're waiting for Opsive to release the new version of Third Person Controller, do you mean their 2.0 version or just a newer 1.3 version? If you're waiting for 2.0 then that won't help really because 2.0 is a separate paid asset and not having integration with 1.3.x would still be missing.
     
  3. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    It's set to Never attack the player.
     
  4. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm seeing a strange issue where when I assign an animation to the AI, it internally assigns some default animation from Emerald AI instead. See image below where I've selected Bear_Idle for my animation, but it thinks I've selected Idle 1. I can't get this to go away. I've cleared the animation controller, deleted it, and started over, but this still keeps happening.

    upload_2018-3-29_21-34-9.png

    If I look at the actual Animator states I can see all the animations for my AI are some default emerald AI ones. I can assign them manually there, but the inspector still complains as if it has the other animations.

    This even happens if I click the Update button and it thinks everything is up to date.
     
  5. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Got Emerald working with raycast based attack :)


    @BHS
    Emerald will need an option to add starting effect for attacks (melee and ranged).
    For example muzzleflash, magic spell charging, melee attack charge particles effect.
     
    Last edited: Mar 30, 2018
  6. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Anyone know when this will support unity 2018? quite a few LOD compile issues.
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    To anyone interested, I started doing integration with Opsive's Third Person Controller last night. The integration is extremely easy. I put together a script called OpsiveBridge that you just have to add to your AI component along with a simple layer change and the addition of specifying a damaged event for each weapon. I will be creating an EmeraldAIBridge script to attach to the player so that AI can damage the player next. Once I have both working, I'll post them here with notes on how to use them if anyone is interested.
     
    zenGarden and TonyLi like this.
  8. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I wonder how many people are using Emerald in a commercial game project ?
     
  9. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I don't know, but I'm using it and my game is commercial. So at least one. :)
     
  10. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Me too for rpg like game, so i'm not the only considering it good enough for commercial usage.

    I started modifying it for modern based weapons game, but it is hard coded and linear in a way it's hard to bring new modules without breaking something :
    - continuous attack for firing
    - continuous muzzle flash effect when firing
    - reload
    - new attack damage function using a delay
    - ability to decide to use an available cover object

    Emerald_AI would need to be splitted in modules to become a general AI able to get new features or addons in a easy way without needing to modify the main class. I don't put big hopes in that lol
    At least Emerald is doing great for what it has been designed.
     
    magique likes this.
  11. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    same here [commercial], I've made quite a few custom changes, but some of which may be added later - working on network integration at the moment, slowly but surely.
     
    zenGarden and magique like this.
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    OK, so here is a basic integration of Opsive if anyone is interested. First thing is to change your Emerald_AI agents to the Enemy layer. Then attach the following script to your Emerald_AI agents:

    Code (CSharp):
    1. using UnityEngine;
    2. using Opsive.ThirdPersonController;
    3.  
    4. public class OpsiveBridge : MonoBehaviour
    5. {
    6.     private Emerald_AI _emeraldAI;
    7.  
    8.     private void Awake()
    9.     {
    10.         EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject>(gameObject, "Damaged", ApplyDamage);
    11.         _emeraldAI = GetComponent<Emerald_AI>();
    12.     }
    13.  
    14.     private void ApplyDamage(float amount, Vector3 point, Vector3 normal, GameObject originator)
    15.     {
    16.         if (_emeraldAI != null)
    17.         {
    18.             _emeraldAI.Damage((int)amount, Emerald_AI.TargetType.Player);
    19.         }
    20.  
    21.         //Debug.Log(this.name + " took " + amount + " damaged at location " + point + " with normal " + normal + " from object " + originator);
    22.     }
    23. }
    On your weapon objects such as Katana, go to the Impact Options and fill in the Damged Event with "Damaged".

    At this point you should be able to kill emerald AI agents.

    For the agents to be able to fight back, it requires changes to the Emerald_AI script similar to other integrations. In the DamagePlayer function add the following code:

    Code (CSharp):
    1.         if (CurrentTarget != null && CurrentTarget.GetComponent<Opsive.ThirdPersonController.Health>())
    2.         {
    3.             CurrentTarget.GetComponent<Opsive.ThirdPersonController.Health>().Damage(CurrentDamageAmount, transform.position, Vector3.zero, 0f);
    4.         }
    5.  
    I believe that's everything.

    [EDIT]
    Also, make sure that the Emerald AI agent has its detection layer set to Player.
     
    Last edited: Jul 7, 2018
  13. Demonoid74

    Demonoid74

    Joined:
    Jan 20, 2017
    Posts:
    16
    Is there currently an included script for healing? one you can attach to health pickups or spells etc?
    I had my own health system working with playmaker , but after I started using this , I deleted it since the AI
    was working and damaging the player...now can't get any healing to work. I am sure I am doing something wrong with trying to call currentHealth and use that in playmaker...

    But hey , if there isn't , a nice easy script you can stick on your pickup items and spells for you , npcs and your companions would be a cool addition...
     
  14. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    For Emerald player you must change PlayerHealth script to detect collision with some healing item and add health points to the variable currentHealth. For npc you do the same in Emerald_AI script.
    For a spell action it's the same way but you don't detect collision and directly add health points to the spell target.
     
  15. hsxtreme

    hsxtreme

    Joined:
    Apr 14, 2017
    Posts:
    55
    I'm using Emerald AI with RFPS, but when I shoot at enemies from a distance they ignore the attacks. Is it anyway or do you have any option for them to discover the player after attack?
     
  16. pickle_rick1

    pickle_rick1

    Joined:
    Jan 7, 2018
    Posts:
    9
    emerald 2.0 had no errors yesterday but today I keep getting Assets/Emerald AI 2.0/Scripts/Editor/PlayerHealthEditor.cs(71,25): error CS0143: The class `UnityEngine.AudioClip' has no constructors defined
     
  17. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @BHS In an effort to improve performance for my game I started to look closer at the Emerald AI code and it seems to me that you are doing a lot of wasted processing. For example, instead of passive triggers to determine if the AI has found targets, you are performing active checks in SearchForTargets using physics spherecast every frame. I am planning to re-write this section to use sphere colliders at search range and they will fire when the player causes the OnTriggerEnter to occur. In this manner, the AI doesn't have to be processing those spherecasts every frame. If a line of sight is required then when the OnTriggerEnter is fired, it can do line of sight checks every so many frames and quit checking when OnTriggerExit occurs.

    I haven't tried this yet, but I suspect I could get a huge performance boost from this approach.

    [EDIT]
    My analysis of this was incorrect so my apologies to @BHS. Please ignore this.
     
    Last edited: Apr 3, 2018
    zenGarden and AGregori like this.
  18. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I think to make a boss enemy using Emerald AI. Is it possible to create multiple custom ranged attacks? But I mean, not only direct ranged attacks? (I mean a custom attack like try 3 fireballs at the same time that fly parallel at each other OR an area explosive attack that is initiated in the player's position)

    Is it possible to mix melee and ranged attacks in one Emerald AI enemy?
     
  19. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I didn't check that part of code. Still i agree a sphere collider is better indeed and it's a cheaper and common way used in Unity. You could collaborate with @BHS so all users will benefit new performance improvements.
     
    Last edited: Apr 3, 2018
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I also have another idea for time slicing the AI processing so that each AI unit gets a different time slice to process on and then you could have say 10-20 AI which only take up the same processing as 1-2 AI. If it all works out I will be sure to share my code with BHS so he can integrate for others.
     
    julianr and zenGarden like this.
  21. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Ugh! I think I was wrong. I only looked at the code briefly and now I see that he's calling the SearchForTarget in the OnTriggerEnter function. I thought I saw it being called from Update somewhere. But I only looked quickly for a brief time. Oh well.
     
    julianr likes this.
  22. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    There is already some sort of tick functionality.


    I see another possible performance improvement in function LineOfSightDetection.
    It loops through all possible AI aorund
    Code (CSharp):
    1. foreach (Transform T in LineOfSightTargets.ToArray()){
    1) Before doing Raycast loop test, all AI with a faction that is not not enemy or neutral should be discarded.
    2) when a first valid target is found, the loop should do a break to stop doing raycast to remaining list objects.
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Yeah, I saw the tick function, but I'm not sure that spreads the AI processing out. Meaning, if the tick is .1 then do all AI get the processing on the same interval? I was going to insure they were on different time slices. But, again, I could be wrong. I've only done a cursory look at this.
     
  24. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    It's perhaps random, each objects Update perhaps doesn't happen in exact same time ?

    The best way to distribute not dependent on AI number would be to use a Raycast manager.
    Each object needing a raycast will query a raycast to the Raycats manager with a priority value
    - 1 : must be done on the frame
    - 2: can wait some frames
    - 3 : can wait half second or later
    The raycast manager processes a number of raycast per frame (min and max possible) you choose.
    And it process first the higher priorities Raycast queries.
     
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I don't know. I can't find that setting anymore now. Where is it and what is it called? I want to check the code to see how it works.
     
  26. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    You have an adjustable variable RayCastUpdateSeconds used for Alignment and Obstruction checks per seconds.
    On top of that there is other possible Raycast calls, but they are not used at same time.

    Do you get some performance issues ? I noticed some hip cups some time , but performance was rather good with many active AI at same time.
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Yeah, I found that just a few minutes ago, but I thought I saw something in the inspector once where you could set a value. It might have been another component though. I'll try the low setting here and see it that helps any.
     
  28. FlyMario

    FlyMario

    Joined:
    Apr 30, 2013
    Posts:
    13
    We cannot seem to get to the Script Reference at all. The web page doesn't respond. Could you please fix this as I need to get this printed out and review it as there is a lot to the script.
    Thanks
    FlyMario
     
  29. AGregori

    AGregori

    Joined:
    Dec 11, 2014
    Posts:
    527
    Incredibly, folder paths are still hardcoded in Emerald_AI_editor.cs: I have to manually edit the script if I want to move the asset from the root. Am I missing something?
     
  30. SolarFalcon

    SolarFalcon

    Joined:
    Nov 28, 2015
    Posts:
    170
    Thanks for the response, I've been busy so I didn't have time to respond.

    Not really sure how many I will need ATM but if 15-30 can be handled at once I'm sure this will be fine. I'll give this a try soon, thanks!
     
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    You need to set your Expanded Detection Radius higher. This will allow the AI to expand its detection if it is hit and no target is initially found.


    Strange, I just tested the script reference page it's working on my end. Try this link here to see if it's working. If not, let me know and I'll find out what's going on.

    http://www.blackhorizonstudios.com/docs/emerald-script-reference/functions/damage/


    It sounds like you are using Unity 2018, correct? I will be sending out an update to fix this issue before 2018 is released.


    Right now, the ranged attacks go in order. I will be improving this by allowing users to customize or randomize the way attacks are picked. Currently, an AI can only use ranged or melee attacks. I will be adding the ability to to have a switched with the next update.


    If I remember correctly, this is needed for creating and saving Animator Controller. However, I can certainly see if I can fix this with the next update.
     
  32. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I use UFPS and Realistic FPS Prefab. Is it possible to create an AI like this one using Emerald AI
    - look for attacks between 30 and 40 seconds
     
  33. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @claudiorodriguescampos I watched the AI in the video and what you have there is more of a scripted AI. So, it basically follows a set sequence of attacks and may at some point escalate to additional attacks. Whereas in Emerald AI your AI are more or less autonomous. You don't have that kind of control. You basically let them loose in the world and they attack, defend, and flee based on their parameters. With a scripted AI, you are probably better off just using something like Playmaker or Behavior Designer. Although in some cases you can use Playmaker/BD in conjunction with Emerald AI to get more complex behaviors.
     
  34. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I will use Emerald AI for simple enemies and I think I will need to find another solution for a boss battle. Thanks for the explanation.
     
  35. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    No problem. I'm in the same boat. I use Emerald AI for my regular enemies and I'm going to use BD or Playmaker for Bosses. But I also use Playmaker along with Emerald for some regular enemies. For example, I have skeletons, which I use Playmaker to fire a dust spurt particle effect, trigger the skeleton getting up animation, and then activate the Emerald AI component. So with Core GameKit it spawns a skeleton, which appears to burst from under ground and get up and then from that point, Emerald AI takes over and they attack per Emerald AI parameters.
     
    Mark_01 likes this.
  36. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    Great implementation idea. I don't llike to use PlayMaker, I use it in the past and it not works for me. I will see if I use BD or other Visual Scripting Tool.
     
  37. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Understood. I had Playmaker for a long time before I got any actual use out of it. For me, it's actually easier to understand the flow of than BD, but BD has some great features especially when you add on the movement, tactical, and formations packs. And BD is faster.
     
  38. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    Good to know that BD is faster. Will take a look on it.
     
    Last edited: Apr 5, 2018
  39. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @BHS I really need to figure out what is causing performance issues in Emerald AI or I might have to move to something else. I thought it was performing well, but my recent test has me very concerned. I have a dungeon scene that is getting 60 fps on the Wii U, but when I place 6 of the demo skeleton AI in the scene fps drops to 20. I have these AI spread out over 3 rooms so only 2 at a time. The first concern is that I'm seeing 20 fps from them even when I haven't even gotten within sight of the first 2. After I kill 4 of them off then my fps goes back up closer to 60. If I keep the skeletons in the scene, but just disable the Emerald_AI scripts on them then the fps is back to 60. Something is horribly wrong.

    [EDIT]
    I decided to do some comparison testing and made a scene with a simple ground plane, a sky, my UMA 2 player character and 6 of the skeleton AI from Emerald AI. In this outdoor scene, the fps is 60 fps even with all AI visible and active. This makes me think that the performance issue is related to scenes with lots of enclosing geometry. So, the question becomes what is Emerald AI bottlenecking on when there is geometry all around it that it wouldn't do with an open area? The answer to this could solve this issue and benefit everyone I think.

    [EDIT 2]
    I double the AI in the outdoor scene to 12 units and still getting 60 fps with occasional dips to 58. Very encouraging, but indoors is some kind of strange problem.
     
    Last edited: Apr 6, 2018
    julianr likes this.
  40. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Dips in frame rate for interiors is a concern of mine too - whilst I've yet to test this and I'll be spawning in and out AI, or using a hibernator to stream in/out AI within interiors, I may have a few floors populated with AI at any given time. I'll come back with my results on this soon also. See if we can compare notes.
     
  41. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Just be aware that if you have a modern PC rig then you might not notice anything without digging deep into profiling. I'm running on the Wii U where such performance issues are always magnified.
     
    julianr likes this.
  42. FlyMario

    FlyMario

    Joined:
    Apr 30, 2013
    Posts:
    13
    So I have a companion caster that is immobile. I pull mobs over to it and it starts shooting them... terribly fun. I have a problem though, even though I tell the mob to have 0 for move speed and run speed it will sometimes just burst into movement. It looks like it runs towards the dead creature then suddenly stops.
    I even added this if (WalkSpeed > 0) { around line 1341 down to about 1372 to block movement. Another place I added the same at around line 1718 to block that section as well if move speed is 0 or below. This did not help.

    Any idea what might be going wrong. I have no walk or run animations on the caster so that isn't what is moving it.

    Incidentally setting the wandering to Stationary does not stop this effect.

    Ok, so I actually solved the issue and posted it on youtube.


    Thanks,
    FlyMario
     
    Last edited: Apr 7, 2018
  43. AGregori

    AGregori

    Joined:
    Dec 11, 2014
    Posts:
    527
    I'm thinking it may be caused by a combination of Dynamic Waypoints calculations and NavMesh calculations in an enclosed space: these can add up severely.
     
  44. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Hmmm. I hope there is a solution to it. I'm experimenting now with using Behavior Designer as an alternative. With that I can also switch to Apex Path if nav mesh is a part of the problem.
     
  45. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    collision and raycasts too :)
     
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I also tested Emerald AI versus ICE Creature Control and Emerald AI was much faster. ICE was even bringing the PC to its knees with the indoor scene.
     
  47. GWStudio

    GWStudio

    Joined:
    Sep 27, 2016
    Posts:
    109
    does this ai (emerald ai v2.0 )have:
    1_ find cover feature.
    2_ ai start wondering and searching when he see his friend in team dead.
    3_ hear e.g. bullet sound and bullet impact on surface in his hear area.
    4_ player can hide in shadow or dark without get detected.
    i hope someone answer ,,,
     
  48. AGregori

    AGregori

    Joined:
    Dec 11, 2014
    Posts:
    527
    That's partly because pooling is famously broken in ICE (still doable with 3rd party pooling assets, I just use UFPS's internal pool manager).
    The truth is that BD blows both Emerald and ICE out of the water in terms of optimization and functionality, but it takes ages to set up and to master.
     
  49. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    How to setup use non ai? The ai walks up to the cube and does nothing, it wont attack and from debugs its not settings the target type .

    else if (TargetTypeRef == TargetType.NonAITarget){
    //Custom code can be added here.
    if (TargetInView){
    DamageBuilding();
    }
    }

    public void DamageBuilding()
    {
    //Do damage against Buildings
    if (CurrentTarget != null && CurrentTarget.GetComponent<Jims_BuildHealth>() != null){
    CurrentTarget.GetComponent<Jims_BuildHealth>().DoDamage(CurrentDamageAmount);
    }
    }

    none of these get called


    //EDIT: Forgot this, I had the building layer on its ignore layer and had the ai attack distance and too cose settings to low :D

    Thank You :D Awesome!!!!
     
    Last edited: Apr 7, 2018
  50. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I don't think it has anything to do with pooling. I just duplicated the AI in the scene and didn't use any pooling.

    Yeah, I'm going to experiment with BD. If I put all the basic animation control into my own script and just trigger them when needed from BD, I think I can have a pretty robust solution with little effort.