Search Unity

[RELEASED] Emerald AI 2.3 - 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:
    3,955
    Hey there. For spawning, if you already own Crux Spawner, I have built-in weather, time of day, and seasonal spawning for UniStorm. Spawning is a bit more complicated than a schedule system as there are many mechanics that would need to be written. I can't provide an in-depth example, but if you are looking for a small example for API to use, you could do something like this. Despawning could be handled similarly.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UniStorm;
    6.  
    7. public class UniStormTimeSpawning : MonoBehaviour {
    8.  
    9.     public float SpawnInterval = 5;
    10.     public List<GameObject> DaySpawnObjects;
    11.     public List<GameObject> NightSpawnObjects;
    12.  
    13.     private void Start()
    14.     {
    15.         InvokeRepeating("TimeSpawning", 0.1f, SpawnInterval);
    16.     }
    17.  
    18.     void TimeSpawning ()
    19.     {
    20.         if (UniStormSystem.Instance.CurrentTimeOfDay == UniStormSystem.CurrentTimeOfDayEnum.Day)
    21.         {
    22.             Instantiate(DaySpawnObjects[Random.Range(0,DaySpawnObjects.Count)], transform.position, Quaternion.identity);
    23.         }
    24.         else if (UniStormSystem.Instance.CurrentTimeOfDay == UniStormSystem.CurrentTimeOfDayEnum.Night)
    25.         {
    26.             Instantiate(NightSpawnObjects[Random.Range(0, NightSpawnObjects.Count)], transform.position, Quaternion.identity);
    27.         }
    28.     }
    29. }
    30.  
    31.  

    As for schedules, here's an improved example schedule system based off of the one I wrote a couple of weeks ago. It uses idle animations and the OverrideIdleAnimation function to allow you to control which animation is played while the AI is in its current schedule. It allow you to create a list of schedules each with the ability to set the hour the event will happen, the idle animation used, and being able to set the Wandering Type to Stationary or Dynamic. I plan on expanding this with built-in API the 2.4 update, but this should give you a general idea of how to accomplish this for now.

    How to use - Just attach it to your AI you would like to have a schedule and assign a transform for each schedule location.

    UniStorm Hourly Time of Day Schedules (Updated to be compatible with v2.3):
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using EmeraldAI;
    6. using UniStorm;
    7.  
    8. public class UniStormAIScheduleByHour : MonoBehaviour
    9. {
    10.     public int StartingEventIndex = 1;
    11.     public List<ScheduleEvent> ScheduleEvents = new List<ScheduleEvent>();
    12.  
    13.     [System.Serializable]
    14.     public class ScheduleEvent
    15.     {
    16.         public int HourOfEvent = 12;
    17.         public enum WanderType { Dynamic = 0, Stationary = 3 };
    18.         public WanderType ScheduleWanderType = WanderType.Stationary;
    19.         public Transform ScheduleLocation;
    20.         public int IdleAnimationIndex = 1; //Idle animations are 1 through 3
    21.     }
    22.  
    23.     EmeraldAISystem m_EmeraldAISystem;
    24.     EmeraldAIEventsManager m_EmeraldAIEventsManager;
    25.  
    26.     void Start ()
    27.     {
    28.         m_EmeraldAISystem = GetComponent<EmeraldAISystem>();
    29.         m_EmeraldAIEventsManager = GetComponent<EmeraldAIEventsManager>();
    30.         UniStormSystem.Instance.OnHourChangeEvent.AddListener(() => UpdateAISchedule());
    31.         GetComponent<EmeraldAISystem>().ReachedDestinationEvent.AddListener(() => ActivateIdleAnimation());
    32.         StartCoroutine(InitializeSchedule());
    33.     }
    34.  
    35.     //Initialize our schedules, but only when UniStorm is initialized.
    36.     //Because the events are based on the hour, the starting schedule will be based off of the StartingEventIndex.
    37.     IEnumerator InitializeSchedule ()
    38.     {
    39.         yield return new WaitUntil(() => UniStormSystem.Instance.UniStormInitialized);
    40.  
    41.         m_EmeraldAIEventsManager.ChangeWanderType((EmeraldAISystem.WanderType)ScheduleEvents[StartingEventIndex].ScheduleWanderType); //Set our AI's Wandering Type using the StartingEventIndex
    42.         m_EmeraldAISystem.m_NavMeshAgent.ResetPath(); //Reset our path so the previous destination doesn't interfere with the new one
    43.         m_EmeraldAIEventsManager.SetDestination(ScheduleEvents[StartingEventIndex].ScheduleLocation); //Set our destination using the StartingEventIndex
    44.         m_EmeraldAISystem.StartingDestination = ScheduleEvents[StartingEventIndex].ScheduleLocation.position; //Set our dynamic wandering destination using the StartingEventIndex
    45.         m_EmeraldAIEventsManager.OverrideIdleAnimation(ScheduleEvents[StartingEventIndex].IdleAnimationIndex); //Set our Idle Animation Index using the StartingEventIndex
    46.         m_EmeraldAISystem.WaitTime = 2; //Dynamic - Set our Wait Time to 2 so the AI starts its animation 2 seconds after arrive to its new destination
    47.         m_EmeraldAISystem.StationaryIdleSeconds = 2; //Stationary - Set our Wait Time to 2 so the AI starts its animation 2 seconds after arrive to its new destination
    48.     }
    49.  
    50.     //This is called once every UniStorm hour usuing a UniStorm OnHourChangeEvent.
    51.     void UpdateAISchedule ()
    52.     {
    53.         if (!m_EmeraldAISystem.IsDead)
    54.         {
    55.             for (int i = 0; i < ScheduleEvents.Count; i++)
    56.             {
    57.                 if (UniStormSystem.Instance.Hour == ScheduleEvents[i].HourOfEvent)
    58.                 {
    59.                     m_EmeraldAIEventsManager.ChangeWanderType((EmeraldAISystem.WanderType)ScheduleEvents[i].ScheduleWanderType); //Set our AI's Wandering Type for this time of day
    60.                     m_EmeraldAISystem.m_NavMeshAgent.ResetPath(); //Reset our path so the previous destination doesn't interfere with the new one
    61.                     m_EmeraldAIEventsManager.SetDestination(ScheduleEvents[i].ScheduleLocation); //Set our destination for this time of day
    62.                     m_EmeraldAISystem.StartingDestination = ScheduleEvents[i].ScheduleLocation.position; //Set our dynamic wandering destination for this time of day
    63.                     m_EmeraldAIEventsManager.OverrideIdleAnimation(ScheduleEvents[i].IdleAnimationIndex); //Set our Idle Animation Index for this time of day
    64.                     m_EmeraldAISystem.WaitTime = 2; //Dynamic - Set our Wait Time to 2 so the AI starts its animation 2 seconds after arrive to its new destination
    65.                     m_EmeraldAISystem.StationaryIdleSeconds = 2; //Stationary - Set our Wait Time to 2 so the AI starts its animation 2 seconds after arrive to its new destination
    66.                 }
    67.             }
    68.         }
    69.     }
    70.  
    71.     //Sets our Idle Active to true when our AI arrives at its schedule destination.
    72.     void ActivateIdleAnimation ()
    73.     {
    74.         GetComponent<EmeraldAISystem>().AIAnimator.SetBool("Idle Active", true);
    75.     }
    76. }
    77.  
     

    Attached Files:

    Last edited: Sep 19, 2019
    ellisthemiracle likes this.
  2. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    @MagiSoftworks im sure BHS will comment on this, but i use UFPS v1.7.5 (as the documentation lists), not sure about v2.0, it might not be that different.
     
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Hey there. Thanks! The integration tutorial covers UFPS version 1.7.5. I don't know exactly what's different with version 2.0 so the integration may not work correctly. The setup process should be the same, but the variable and script names might be a little different.
     
  4. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    Hi Again - :) I went ahead and integrated Invector which seems to be working great with the script mod's. Problem is My EAI character will start walking or running and after 5 or so steps continues to move and turn but the walk or run animation are not longer working (Ice Skate mode).-When he detect me same thing but the attack animations kick in fine, If he Starts to move back - Again 5 steps then the ice skating begins. I checked all animations on Loop- Agent Turn speeds, Baked NavMesh is on simple small test terrain. FYI - He even does this while doing Idle with wander type on dynamic - 5 steps then skating. Gotta be missing something stupid. lol
     
  5. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Great to hear you got it all integrated. If your AI start sliding, and you’ve double checked that all needed animations are set to loop, then you may be missing an animation somewhere. It sounds like it’s one of your idle animations so make sure they are all applied and that none of the slots are missing animations.

    Your AI’s attack and stopping distance may also be too small which would have the AI play its idle animation before it’s done moving. Making these values bigger may also help.
     
  6. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    Thanks Again! Don't know how I missed it, Default play time setting on one Animation for this AI was ridiculously small. :) Having good time with EAI though -
     
    BHS likes this.
  7. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    74
    I had to recreate my ranged AI, not sure what happened but one worked while the rest didn't. So i just recreated and they all turn right now.
     
  8. pjccccc

    pjccccc

    Joined:
    Oct 7, 2015
    Posts:
    41
    For someone who wants to use Emerald AI with UNET (maybe Photon).

    It just took 30 mins for me, I attached `NetworkAnimator` and `NetworkNavMeshAgent(which is not officially provided)`.
    and made some code modifications.
    (Just keep in mind that entire AI processing must be executed in server, client only replicates the animations)

    * Change every `SetTrigger` and `ResetTrigger` to `RpcSetTrigger` and `RpgResetTrigger`. You have to implement `Rpc~~` methods, it just 1 or 2 lines of code.

    * Add `Server` attributes to server specific methods such as `EmerandAIDetection.Update`.

    * `ai.Damage(...)` must be called on the server-side.

    Hope EmeraldAI officially support UNET.
     
    Last edited: Sep 2, 2019
  9. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    Nice bro!
     
  10. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
    @BHS Is there a way to get AI to utilize more than a single box collider? I have a deer and I added another box collider for the head, but it is totally ignored.

    upload_2019-9-2_9-2-29.png
     
  11. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    Have you tried using a different collider other than another box?
     
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
    Nope, I haven't.

    [EDIT]
    Now I tried Capsule Collider and same result. It seems that Emerald AI uses only the one generated box collider. I pause the game and the second box collider has been disabled. If I then re-enable it then it works. So, I need to figure out where emerald is disabling the additional collider. Not sure why it would do that.
     
    Last edited: Sep 2, 2019
    warthos3399 likes this.
  13. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
    @BHS Another issue I'm seeing is AI alignment to terrain. I've set my deer AI to align to the terrain, but it's aligning in the opposite direction. I've checked and the model is pointing forward in the direction of the blue arrow, but the alignment is reversed.
     
  14. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Great to hear everything is working correctly.
     
  15. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Thanks for making this guide to add UNET support.

    I do plan on adding network support, but since UNET is being/has been deprecated, the support for it will be offered through tutorials or external code. I will also cover other network solutions such as Photon and Mirror.
     
  16. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    The ragdoll initializer currently disables all colliders within an AI. I plan on adding the ability to use the ragdoll colliders for location based damage after 2.3. The only way to get this to work now would be to modify the code to not disable the colliders within the AI and set them to a layer that the AI's Obstruction Ignore Layer uses so they don't interfere with the detection process.
     
  17. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    That's strange. Every AI I've tested has alignment working correctly with both biped and quadruped types. Is this happening during the wandering, fleeing, or fighting behavior?
     
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
    It happens everywhere and always. Whether it's just standing there on a hillside or running around.
     
  19. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
    OK, I'll do that then.
     
  20. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    I can't seem to recreate this. Everything is working properly on my end. Have you tried using a different model?
     
  21. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,585
  22. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Hey everyone,

    I plan on having Emerald AI submitted by the end of this week!

    While the previous version of Emerald AI focused on RPG AI, Emerald AI version 2.3 will be much more flexible allowing users to create nearly any type of AI, even shooter type AI with guns. With that being said, Emerald AI still fully supports animal based AI and version 2.3 will include a dynamic grazing and resource gathering system allowing AI to generate waypoints to food, water, or other resources. More information on this can be found here: https://forum.unity.com/threads/rel...lls-blocking-more.336521/page-73#post-4882796

    This video shows how version 2.3, and its new modular ability system, makes it easy to create nearly any type of weapon or projectile for your AI, even bullets, lasers, and rockets. The AI look at feature has also been rewritten to be a lot more responsive and accurate. It will also now smoothly transition to new targets.

    (Character Models by PROTOFACTOR, INC Lighting and Clouds by UniStorm)


    The updated Ability Object editor has been split into 3 categories. Support has been added for critical hits as well as damage over time. The above video shows the versatility of Emerald AI's new ability system. One of the best features of version 2.3 is that ability objects can be shared between AI and projectiles are no longer tied to each of an AI's editor like it is currently. (The name Spell will be renamed to Ability when Emerald AI is released to make the system more general)
    AbilitiesEditorUpdated.gif
     
    Last edited: Sep 3, 2019
  23. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    265
    Geez, put in a cover syatem and this thing is gold haha
     
    gearedgeek, SickaGamer and julianr like this.
  24. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,108
    @BHS yes, agree with this, it would make Emerald a top choice with a solid background to boot - 2.3 is looking awesome by the way! Can't wait to try it out!
     
    gearedgeek and SickaGamer like this.
  25. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    739
    Looks great @BHS ! I agree that a cover system would be awesome for 2.4 :)
     
  26. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    Wow BHS- you went to town on 2.3! Looks amazing. Great work!
     
  27. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Thanks everyone!

    I agree with a cover system feature. After 2.3, I'll start looking into how to go about implementing one.
     
    gearedgeek and julianr like this.
  28. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Thanks! :)
     
  29. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    Love it @BHS, lookin damn good, cant wait for the update, as the added features will work in nice with my next project after Jurassic Extinction. :)
     
    BHS likes this.
  30. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    491
    More importantly, I would like EmeraldAI to be able to be extended through APIs. Right now, it seems like I'm working with a blackbox AI. If so, we can add new behaviors if we want without waiting for EAI to support.
    Any work being done toward to extendable AI system?

    Thanks.
     
    warthos3399 likes this.
  31. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    Non - Combat EAI animation:

     
    BHS, Mad_Mark and huntersteeger like this.
  32. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    384
    Nice work. Are you making the quadruped animations yourself, or are they an asset? I've tried making a set of dog animations for a companion AI, and after learning my own limitations, have searched all over. The few that I have found are not transferable to other dogs, very skeleton specific. What are you (and others) doing for quad-anims?
     
  33. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    most all models have a good amount of animations (stand, Walk, Attack, idle, Die, etc.), EAI works great with any animation, alot of control.

    Dog animation...ive seen some here and there, but not alot out there.
     
  34. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Emerald AI is pretty flexible. I've been able to create 2 external systems recently without having to alter any Emerald AI system code which expand an AI's behavior and functionality such as this waypoint generator to food, water, and resources: https://forum.unity.com/threads/rel...lls-blocking-more.336521/page-73#post-4882796 and this schedule system to give an AI the ability to move between destinations depending on the time of day: https://forum.unity.com/threads/rel...lls-blocking-more.336521/page-76#post-4916207

    I'm more than happy to expand the API further and Emerald AI is getting more modular with each update. What kind of behaviors or functionality are you trying to achieve?
     
  35. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    491
    Hi, thanks for the answer. I think the best is to make EAI API modules/ability callable externally so that behavior system like NodeCanvas or BehaviourDesigner can call them.
    This will make EAI very flexible and powerful.
    Cheers!
     
  36. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    You’re welcome.

    Almost all of Emerald AI’s API is callable externally. It’s done through the EmeraldAIEventsManager script and you can change an AI’s behavior, confidence, destination, waypoints, play animations, and tons more. I haven’t tested this with NodeCanvas or Behavior Designer, but it works with PlayMaker so the process should be similar with other systems that can access a system’s API. If something isn’t working correctly with NodeCanvas or Behavior Designer though, I’m more than happy to resolve it.
     
    attaway likes this.
  37. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    384
  38. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    338
    Good day. Make it possible to move creatures dynamically. I mean without using NavMesh.
     
  39. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    Looks great Warthos! I like how you share updates on your work - nice.
     
    warthos3399 likes this.
  40. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    BHS- So we may see 1.3 this weekend? :) Would be perfect timing while Dorian has us hunkered down.
     
  41. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Thanks Mark, I had planned on linking this, but forgot. I will be creating a new example scripts doc after the release of 2.3 to show more complex examples of what's possible with Emerald AI. Feel free to let me know if there are suggestions for improvements with the docs and API.
     
  42. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Emerald AI is currently dependent on NavMesh. However, I can look into a non-NavMesh option with a future update.
     
  43. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Not quite :) I'll be working through the weekend to get it submitted by Monday or Tuesday.
     
    julianr and warthos3399 like this.
  44. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    81
    All good :) Appreciate the good work.
     
  45. tahir_ali

    tahir_ali

    Joined:
    Jan 6, 2018
    Posts:
    32
    Using Ranged type attack. It does not attack keeps looking at player. Any help Please? No Exception in console.
     
  46. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    260
    ok, 1st we need more info, what are you trying to animate, and how do you want to animate it?
     
  47. tahir_ali

    tahir_ali

    Joined:
    Jan 6, 2018
    Posts:
    32
    Its Humanoid archer. Melee types are working fine.
     
    Last edited: Sep 7, 2019
  48. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    Are you using a character controller from the Asset Store or a custom one?

    Some character controllers have extra colliders that may obstruct your AI’s line of sight. Try enabling the Debug Tools and set all of the debug options to Yes on your AI. These are located under the Docs tab near the bottom.

    These will debug log the AI’s current target and obstructions so you will have a better idea of what’s going on. Ensure that the proper player object is being target. If it isn’t, you will need to either disable the obstruction object or add its layer to the AI’s Obstruction Ignore Layers located under the Detection Settings.
     
    tahir_ali likes this.
  49. pccross

    pccross

    Joined:
    Jun 20, 2015
    Posts:
    87
    So after a bit more investigation, looks like the rigidbody on the AI being set to 'Is Kinematic' was part of the problem, and why the character didn't respond to bullets (via 'AddForce'). However, if I turn off this 'Is Kinematic' setting, the AI's fall sideways, and run almost parallel to the ground, so guessing that's not right way to fix this. Hopefully, missing a simple setting somewhere. Any other suggestions?
     
  50. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    3,955
    If you are trying to achieve location based damage, and have colliders with rigidbodies on the children part of the AI, they are deactivated on start as part of the ragdoll initialization process. If they are not disabled, they will interfere with the AI’s detection functionality. I’m working on location based damaged with the update following version 2.3.

    What specifically are you using AddForce for when damaging the AI, to physically move the parts hit by bullets? Emerald AI uses one box collider and a Kinematic rigidbody only for collision detection so it doesn’t actually use any physics. The movement is all driven by the NavMesh system. Disabling Is Kinematic will allow it to be moved by Unity’s physics which is why you see the undesired rotation and movement.