Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Emerald AI 3.2 (New Sound Detection) - The Ultimate Universal AAA Quality AI Solution

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

  1. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    If you are using a custom projectile for your player, you will need to grab the Emerald AI component off of the object your projectile colliders with.

    So, depending on your collision method, use the following:

    OnTriggerEnter:
    Code (CSharp):
    1. void OnTriggerEnter(Collider C)
    2. {
    3.    if (C.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>() != null)
    4.    {
    5.        C.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>().Damage((int)YourDamageAmount, EmeraldAI.TargetType.Player);
    6.    }
    7. }
    OnCollisionEnter:
    Code (CSharp):
    1. void OnCollisionEnter (Collision C)
    2. {
    3.    if (C.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>() != null)
    4.    {
    5.       C.gameObject.GetComponent<EmeraldAI.EmeraldAISystem>().Damage((int)YourDamageAmount, EmeraldAI.TargetType.Player);
    6.    }
    7. }
     
    Last edited: Mar 30, 2019
  2. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I can look into this feature. I don't believe it would be too hard. There's a public function with EmeraldAISystem called TargetAngle that detects the current target's angle and returns it. You could add in some custom code to the Damage function to multiply the damage if the target is greater than something like 150 degrees.

    I just tested this and it works, if you're interested:

    1) In the EmeraldAISystem script, find the line:
    Code (CSharp):
    1. DamageEvent.Invoke(); //Invoke our AI's Damage Event
    2) Above the line CurrentHealth -= DamageAmount; add the following code:
    Code (CSharp):
    1. if (TargetAngle() > 150)
    2. {
    3.    DamageAmount = DamageAmount * YourDamageMultiplier;
    4. }
     
    SickaGames1 likes this.
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Yes, here's a script. All you have to do is customize it and ensure the EmeraldAITag matches your AI's gameobject tag. There will also be an included example scene with the next update.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace EmeraldAI.Example
    6. {
    7.     [RequireComponent(typeof(Rigidbody))]
    8.     [RequireComponent(typeof(AudioSource))]
    9.     public class EmeraldAICollisionDamage : MonoBehaviour
    10.     {
    11.         public int DamageAmount = 100;
    12.         public int PushAmount = 400;
    13.         public AudioClip CollisionSound;
    14.         public string EmeraldAITag = "Respawn";
    15.  
    16.         Rigidbody m_Rigidbody;
    17.         AudioSource m_AudioSource;
    18.  
    19.         void Start()
    20.         {
    21.             m_Rigidbody = GetComponent<Rigidbody>();
    22.             m_AudioSource = GetComponent<AudioSource>();
    23.         }
    24.  
    25.         void OnCollisionEnter(Collision C)
    26.         {
    27.             if (C.gameObject.tag == EmeraldAITag && m_Rigidbody.velocity.magnitude > 0)
    28.             {
    29.                 if (C.gameObject.GetComponent<EmeraldAISystem>() != null)
    30.                 {
    31.                     C.gameObject.GetComponent<EmeraldAISystem>().Damage(DamageAmount, EmeraldAISystem.TargetType.NonAITarget, transform, PushAmount);
    32.                     m_AudioSource.PlayOneShot(CollisionSound);
    33.                 }
    34.             }
    35.         }
    36.     }
    37. }
     

    Attached Files:

  4. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Did you use the exact same Tags and Layers as stated in the tutorial video? There's more to the tutorial than just pasting in the code snippets. Also, it looks like you're using a mobile version. Does this use the same scripts as the non-moble version?
     
  5. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Right on dude. Something to add in for a public variable in a future update too.
     
  6. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    @BHS Are there tutorial videos on how to setup Projectile Ranged AI? I set mine up and can't seem to get the projectile to trigger during attack. Everything works great except the projectile wont activate at the point of attack-animation.
     
    Last edited: Apr 1, 2019
  7. Dionysos1111

    Dionysos1111

    Joined:
    Feb 14, 2016
    Posts:
    39
    I see that the healthbars show up when the player comes in the detection distance.
    I want the healthbars to show up before the detection distance since the AI starts to attack when the player is in the detection distance.
    I don't see an option for that and i can't find the reference in the code, what is the best way to achieve this?
     
  8. Slakjaw

    Slakjaw

    Joined:
    Jul 25, 2017
    Posts:
    1
    I just wanted to add some comments about threat. I think there should be a threat level for all combat related weapons, spells, and abilities. The accumulation of each players threat should pass the highest to the creature as the target. That way it's proper with all spells (including heals etc...) that build up threat, and other spells or abilities that will lower threat. The creature shouldn't decide though, it should just get the current highest threat player to attack as it's target. This is where you get the fun challenge that really adds to the game like WoW, and where all the other games completely fail using threat. If a healer is spamming heals and the tank isn't getting hurt, the healer should be targeted by the creature. That way you get the healer being more strategic and not just standing there without danger, as well as the tank using their abilities to taunt efficiently. Same with damage spells needing to back off at times while the tank regains threat. If you add this into Emerald AI, you will do what every other game out there has completely failed to do properly to compete with WoW. This is a huge reason why other games just don't feel right and are kinda boring after awhile. The threat management in combat is a sort of mini-game in itself.
     
  9. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17
    Did you use the exact same Tags and Layers as stated in the tutorial video? There's more to the tutorial than just pasting in the code snippets. Also, it looks like you're using a mobile version. Does this use the same scripts as the non-moble version?
     
  10. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17
    upload_2019-4-2_22-6-30.png


    upload_2019-4-2_22-7-46.png

    upload_2019-4-2_22-8-8.png
     
  11. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    The easiest way to think of it, is any “action” wether spell, or attack, melee or ranged, should have an adjustable threat value that when used adds to a threat pool asigned to the player, and monster when choosing a target, look in thier immediate area and choose the highest pool as thier target.
     
  12. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Here's a tutorial for creating ranged attacks. It has been updated to include the steps added with version 2.2. You will need to create an CreateEmeraldProjectile Animtion Event for each of your AI's attack animations. These are what actually trigger a projectile to be created: https://docs.google.com/document/d/...s2njM7Jx9pYlqgbtM8/edit#heading=h.ifb2ybkoddb


    I plan on redoing the way some of the UI is handled, including improving the way the UI is enabled. For now, you can control whether an AI's UI is enabled by using the following function on the EmeraldAISystem script.
    Code (CSharp):
    1. SetUI(bool Enabled)

    Thanks for the suggestions. I think these are great ideas. I will certainly look into adding a threat feature with the 2.3 update. I have already implemented a simple aggro system and I will be expanding it with the 2.3 update.


    Everything looks correct. Are you having an issue with AI detecting your player or doing damage? If you are having issues with your AI detecting your player, make sure your AI have AI Attacks Player set to Always. This setting is located under the Detection Options. If your AI are detecting your player, try enabling the debug options to see if the proper target is being detected. This can be found under the Docs tab at the bottom. Make sure all the debug options are enabled.
     
    ZGoodwin and SickaGames1 like this.
  13. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17

    my problem is that I can not damage the enemy with any kind of weapon or firearms, the enemy can detect and attack me and it can do me damages but I do not
     
  14. huntersteeger

    huntersteeger

    Joined:
    Dec 27, 2017
    Posts:
    19
    I could use a little help setting the ragdoll colliders as hitboxes for my agent.
     
  15. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    @BHS Are there any plans to add sleeping animations and "wake-up" triggers to EmeraldAI?

    Currently, I want to add sleeping zombies to my game. They are lying on the ground motionless, looking dead. The player enters a trigger zone, and the zombies stand up and start to move towards the player.

    To quick and dirtily accomplish this, I modified the override controller, adding a sleep animation, just a short loop of the character lying on the ground, and made it the default state. I added a bool "Sleeping" to the animator parameters and set it to true. I also disabled the zombie's NavMeshAgent in code. If the sleeping bool becomes false it connects back to the Movement state. I then made an empty with a trigger collider with an OnTriggerEnter function that changes the sleeping bool to false and re-enables the NavMeshAgent.

    When I hit play, the zombie is sleeping, and when I enter the trigger, it jumps up and activates. Because the NavMeshAgent is disabled in the first frame that it activates, it throws the usual "too far from NavMesh" error. How should I handle this error, or is there a better way to handle this rather than disabling the NavMeshAgent?

    Mark
     
  16. unicat

    unicat

    Joined:
    Apr 8, 2012
    Posts:
    425
    Emerald seems really picky with the animations. I have now a spider in my level with a bite animation and the Animation Event doesn`t work too. Some animation work and some not. Must a animation have some special requirements or settings ?
     
  17. RonnyDance

    RonnyDance

    Joined:
    Aug 17, 2015
    Posts:
    557
    Good question I would have thought that adding the sleeping Animation as idle animation would be sufficient. The Zombie should wake Up and attack when Player is in aggro range. What would be missing is the wakeup / stand Up Animation... Hmm
     
  18. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    You're right, in most cases that would do the trick, except that I have 3 idle animations that play as a regular routine when the zombie is "on the prowl". This way I can have them go dormant whenever I want, lay them down, and have them pop up and scare the crap out of the player. At least once anyway. Mix them up with the bodies that are already lying around. I just turn on the "sleep" parameter with an OnTriggerExit function that calls an IEnumerator to allow the player 30 seconds or so to get out of detection range.

    I am thinking that this is probably how I will do the "eat" function. Right now the zombies attack the NPC citizens that are also Emerald wanderers, kill them, and then move onto the next target. At some point I will need to get them to kill and nibble on the NPC's for some period of time to serve as a distraction from chasing the player. Give them a chance to escape a horde, setup a diversion, or escape from a particularly powerful zombie.

    Yes, I am still tinkering, and had a standup animation in there originally. I think if I delay the NavMeshAgent enable call until after that animation has played, it would work. Right now the transition from prone to standing is rather sudden, but acceptable for dramatic effect.

    Mark
     
  19. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    None that I have found so far, but I am not fiddling with spiders, just humanoid animations. There might be challenges with Generic or Legacy anims, not sure. I will be adding dogs to my game as companions and as enemies, so let me know what you work out. If I get there and find issues/solutions, I will do the same.

    Mark
     
  20. AquaAF

    AquaAF

    Joined:
    Jun 12, 2015
    Posts:
    6
    @BHS Hey, I just wanted to know what's the ETA for a tutorial for UFPS version 2.0. In the UFPS 1.7.5 integration video, the description said that it will be a separate video. I'm just curious so no worries if you are busy.
     
  21. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17
    I come back with my problem if there is someone who can help me solve the problem, which is quite frustrating
     
  22. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS any ETA on when you will be starting 2.3 and what you plan on including in it?
     
  23. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I think I may know what is causing your issue. If your attack animation's Animation Event is called near the beginning of the animation clip, the Animation Event may not be triggering properly. This is a bug with Unity, but it may be fixed by adjusting the Transition Duration to 0.

    AnimationStateSettings.png
     
  24. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I will be adding this feature soon in a future update.
     
  25. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Thanks for providing a quick solution on how to do this.

    I can add a state that will allow a transition to sleeping, a state that will loop the sleeping animation, and a state that will transition out of sleeping. I'll make a public function within the EmeraldAIEventManager script that users can call to enable or disable sleeping. I'll try to get this added asap.

    Wherever the error is, you need to check if the m_NavMeshAgent component is enabled before the code that's causing the error is called.
     
  26. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    There's no special requirements. It's a bug within Unity. An Animation Event cannot be called within the transition/blending phase of a state. To fix this, set the Transition Duration to 0 as I explained in this post: https://forum.unity.com/threads/upd...blocking-and-more.336521/page-63#post-4400293

    If that doesn't work, try adjusting the other settings that control how quickly the animations transition.
     
  27. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    I don't have UFPS version 2.0 and the developer of UFPS hasn't responded to my messages regarding adding support. I'm willing to create the tutorials, I just need them to give me a copy of their asset so I can make them.
     
  28. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    So you got it working and your issue resurfaced? This was regarding you not being able to cause damage to other AI, correct? Are you using the same AI or a different one?

    Also, have you ensured that the Box Collider on your AI are positioned and sized correctly? This component is what detects collisions form RFPS. When setting up, the Setup Manager tries to setup the Box Collider, but it isn't always perfect and often requires some adjustments. My guess is that this is where you are having issues.
     
  29. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    No ETA at the moment, but the 2.3 update will be the update that adds the reworked abilities using scriptable objects.
     
  30. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17

    For this reason ? I can not attack the enemy, I repeat my problem is when I the player I try to attack the enemy, not when the enemy attacks me
     
  31. NextGame22

    NextGame22

    Joined:
    Mar 27, 2019
    Posts:
    17
    I do not know exactly what happened, I reinstalled the unity and rfps and Emerald 2.0 and now works perfectly! if she can tell me how I set the damage done by the weapons, because they shoot it once and die, Thanks a lot for those who tried to help me!
     
  32. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    @BHS I'm getting the following error at runtime:

    <b><color=red>CityGuard (3)'s Attack 1 is missing a SendEmeraldDamage Animation Event. Please add one or see Emerald AI's Documentation for a guide on how to do so.</color></b>
    UnityEngine.Debug:Log(Object)
    EmeraldAI.Utility.EmeraldAIInitializer:CheckAnimationEvents() (at Assets/Emerald AI/Scripts/Components/EmeraldAIInitializer.cs:750)
    EmeraldAI.Utility.EmeraldAIInitializer:Initialize() (at Assets/Emerald AI/Scripts/Components/EmeraldAIInitializer.cs:29)
    EmeraldAI.EmeraldAISystem:Awake() (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:776)

    I didn't see this anywhere in the documentation so I searched the forum and you explain that this needs to be added for each shooter animation. But my AI is only melee combat. Is this required for that as well? I've never had this error come up before.
     
  33. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    I am missing one final step to get the projectile fx the way I need it. Can you tell me which onAttack Event is needed to create a "tracer fx". In other words, I need the projectile fx to fly from point a) to, point b). I'm at a dead end and can't get it working. So far, I've used the following events...

    EmeraldAIEventsManager.SpawnAdditionalEffect
    EmeraldAIEventsManager.SpawnEffectOnTarget

    These events do not provide the heetseeking I need. Instead they only spawn the FX either at the enemy, or directly on the player.

    Thank you
     
  34. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    To use all these new smooth animation tech and blend tree does the animation need to be root motion based or?
     
  35. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    315
    @magique Hmm... Something definitely up with these animation events. Mine are also melee only yet I get the same error (my transitions are set to zero too, as @BHS suggested).

    Also, sometimes my character sinks halfway into the floor and rotates on the spot instead of playing his turning animations. Not sure what causes that as it's hard to recreate.
     
  36. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I'm seeing that a lot too. Also, when I add an animation or update an existing one, there no longer is a button to update the animation controller. I have to clear the old one then create the new one again.
     
  37. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS Someone who do a bandicam vid for BHS.
     
  38. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    That would have been my next suggestion. Sometimes this is all that's needed. It's great to hear everything working correctly. The amount of damage that weapons do can be adjusted on the RFPS weapons.
     
  39. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    A SendEmeraldDamage is required for all melee attacks. A CreateEmeraldProjectile is required for all ranged attacks. This is the best way to get damage and projectiles to fire consistently and reliably. Below is a video tutorial explaining how to do this. Animation Events are covered at the bottom of the Emerald documentation.



    Animator Controllers are updated automatically each time you make a change in the Animation tab (this is explained at the top of the Animation tab) so there's no need to manually press a button to update it. If you, or anyone else, sees their AI drop into the ground, this means you are missing a required animation somewhere.
     
    Weblox likes this.
  40. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Those events, as well as OnAttack events, are not built for firing projectiles. You need to create a CreateEmeraldProjectile Animation Event to have an AI fire a ranged attack. The AI will need to have a Ranged Weapon Type which will make the ranged options visible, including a heat seeking option.

    For a tutorial on creating said Animation Event, please watch this tutorial video.
     
  41. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I double checked and all combat and other movements have all required animations.
     
  42. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    No, Root Motion is not required to use the Blend Trees. However, it will look the best if you use Root Motion as the AI's speed will be driven by the AI's animations.
     
  43. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Have you tried clearing the AI's Animator Controller and creating a new one? What is the AI's Behavior and Confidence set to? I'll try to recreate the issue so I can find a solution.

    When an AI falls through the ground, this indicates that the AI is missing an animation. Can you please double check to see if any animations are missing from your AI in both the Animation tab and its Animator Controller?
     
  44. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,760
    Thanks for checking that. Have you checked your AI's Animator Controller to ensure all of the animations have been correctly applied?
     
  45. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    Videos are worth a billions words folks. Take one and BHS can troubleshoot easier.
     
  46. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,268
    @BHS Do you have the clouds going yet? ;)
     
  47. unicat

    unicat

    Joined:
    Apr 8, 2012
    Posts:
    425
    Setting transition duration to 0 doesn`t help. Maybe it`s a bigger Unity bug with Animation events.
     
    Last edited: Apr 8, 2019
  48. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    No, but I can do that tonight.
     
  49. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Okay cool. What if I use Crux to spawn Emerald AI , is it possible when using terrain streaming?
     
  50. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I checked this and saw some very strange things. The Run animations were not assigned in the override controller. So I manually set them, but they somehow got set back to nothing on their own. After a couple of tries I finally got them to stick. However, the issue is still happening where the AI drops through the ground sometimes.