Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[ON SALE - 50% OFF!] Emerald AI 2.3 - The Ultimate Universal AAA Quality AI Solution

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

  1. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    @unity_7UFP4-iCkwsgjg OK, so here is an example of changing the attack distance using tag to identify as player. This Update code can be placed as part of your AIHelper script that is attached to your AI. Also, note that instead of grabbing the EmeraldAISystem component each time, you could do this once in the Awake() function. You can also change this to only run every so many frames instead. This is just a quick and dirty example.

    Code (CSharp):
    1.         public float playerAttackDistance;
    2.         public float aiAttackDistance;
    3.  
    4.         public void Update()
    5.         {
    6.             var aiUnit = GetComponent<EmeraldAISystem>();
    7.             if (aiUnit.CurrentTarget != null)
    8.             {
    9.                 if (aiUnit.CurrentTarget.tag == "Player")
    10.                 {
    11.                     aiUnit.AttackDistance = playerAttackDistance;
    12.                 }
    13.                 else
    14.                 {
    15.                     aiUnit.AttackDistance = aiAttackDistance;
    16.                 }
    17.             }
    18.         }
    19.  
     
  2. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

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

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Right. Just set the playerAttackDistance to be closer than the aiAttackDistance and it should adjust automatically depending on the target.
     
  4. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    ah still no such luck it still doesn't get close enough it stays at a small distance away
     

    Attached Files:

  5. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Change the Too Close Distance to a much smaller value. You may not even need the script I provided.
     
  6. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    have the too distance at 1 still doesn't get close enough only way it seems to work is if i change the attack distance on the emerald inspect but then my ai can't butt heads against other ai :(
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Doesn't the script help resolve this?
     
  8. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    unfortunately not it keeps away at a gap size distance even at lowest number. My ai butt heads perfectly if i have attack distance set at 60 only but this still keeps my ai from getting to close to my player
     
  9. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    screen shot showing distance
     

    Attached Files:

  10. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    its the to close distance it seems but even setting it at 1 it wont get close enough
     
  11. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    I'm confused. You seem to be able to get it to work for AI and Player, but not at the same time. Is that correct? And you are saying that the attack distance is what needs to be changed to make it work one way or the other. Is that correct? If so, then the script should work because it will change the attack distance for you based on target. If not, can you add debug as follows and let me know what the output is.

    Code (CSharp):
    1.         public float playerAttackDistance;
    2.         public float aiAttackDistance;
    3.         public void Update()
    4.         {
    5.             var aiUnit = GetComponent<EmeraldAISystem>();
    6.             if (aiUnit.CurrentTarget != null)
    7.             {
    8.                 if (aiUnit.CurrentTarget.tag == "Player")
    9.                 {
    10.                     aiUnit.AttackDistance = playerAttackDistance;
    11.                                         Debug.Log("1 Setting attack distance to " + playerAttackDistance);
    12.                 }
    13.                 else
    14.                 {
    15.                     aiUnit.AttackDistance = aiAttackDistance;
    16.                                         Debug.Log("2 Setting attack distance to " + aiAttackDistance);
    17.                 }
    18.             }
    19.         }
     
  12. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    @unity_7UFP4-iCkwsgjg If you want, we can chat on Discord and this might go faster. My Discord name is Magique#8702.
     
  13. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    that is correct. yes that is also correct i have screenshot the debugs from the script you have provided (tried to show best i can as i don't have discord )
     

    Attached Files:

  14. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Discord is a free app. Easy to get and use. It would help if you could chat there.

    As far as your debug, is the AI currently trying to attack the player or is it trying to attack the AI?

    [EDIT]
    And what values do you have for playerAttackDistance and aiAttackDistance?
     
  15. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    285
    if i use
    Code (CSharp):
    1.  public float playerAttackDistance;
    2.         public float aiAttackDistance;
    3.         public void Update()
    4.         {
    5.             var aiUnit = GetComponent<EmeraldAISystem>();
    6.             if (aiUnit.CurrentTarget != null)
    7.             {
    8.                 if (aiUnit.CurrentTarget.tag == "Player")
    9.                 {
    10.                     aiUnit.AttackDistance = playerAttackDistance;
    11.                                         Debug.Log("1 Setting attack distance to " + playerAttackDistance);
    12.                 }
    13.                 else
    14.                 {
    15.                     aiUnit.AttackDistance = aiAttackDistance;
    16.                                         Debug.Log("2 Setting attack distance to " + aiAttackDistance);
    17.                 }
    18.             }
    19.         }
    then the player dosen't get damaged but debugs occur.




    if i use
    Code (CSharp):
    1.  
    2.         public void Awake()
    3.         {
    4.             var aiUnit = GetComponent<EmeraldAISystem>();
    5.             if (aiUnit.CurrentTarget != null)
    6.             {
    7.                 if (aiUnit.CurrentTarget.tag == "Player")
    8.                 {
    9.                     aiUnit.AttackDistance = playerAttackDistance;
    10.                     Debug.Log("1 Setting attack distance to " + playerAttackDistance);
    11.                 }
    12.                 else
    13.                 {
    14.                     aiUnit.AttackDistance = aiAttackDistance;
    15.                     Debug.Log("2 Setting attack distance to " + aiAttackDistance);
    16.                 }
    17.             }
    18.         }
    then damage occurs to player but debugs don't occur


    values for attackplayer is 1 and ai attack is 60. using my otherhalfs discord now will add you:)
     
  16. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Well, based on your last message, then you don't need the script for it to attack the player properly. Because in the case of Awake(), none of the script code would execute because there is no CurrentTarget. So, the question is, what is the AttackDistance set to before you run the game? Whatever that value is is what you need to use for your playerAttackDistance when you have the script in the Update() loop.
     
  17. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    OK, for the final solution to the issue @unity_7UFP4-iCkwsgjg was working on, here is the script.

    Code (CSharp):
    1.     public float playerAttackDistance;
    2.     public float aiAttackDistance;
    3.  
    4.     public void Update()
    5.     {
    6.         var aiUnit = GetComponent<EmeraldAISystem>();
    7.         if (aiUnit.CurrentTarget != null)
    8.         {
    9.             float newAttackDistance = (aiUnit.CurrentTarget.tag == "Player" ? playerAttackDistance : aiAttackDistance);
    10.             if (aiUnit.StartingAttackDistance != newAttackDistance)
    11.             {
    12.                 aiUnit.AIAnimator.ResetTrigger("Attack");
    13.                 aiUnit.StartingAttackDistance = newAttackDistance;
    14.                 aiUnit.AttackDistance = newAttackDistance;
    15.                 aiUnit.m_NavMeshAgent.stoppingDistance = newAttackDistance;
    16.  
    17.                 Debug.Log("Setting attack distance to " + newAttackDistance);
    18.             }
    19.         }
    20.     }
    21.  
     
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Hi, Emerald AI community. I decided today that I'm going to write some Playmaker actions for Emerald AI and make them available to anyone who wants them. I'm not planning to go crazy with it and make every possible action there could be because I mainly need it just for a few specific things in my own project. However, I'd be interested in knowing if anyone else would need such an integration and, if so, what specific things would you want to see in this integration.

    As of now, I created 2 actions for SetMovementType and SetDestination. So you can change movement to Walk or Run and you can specify a destination. I'll also definitely add StopMovement. I also think it would be useful to switch from Melee to Ranged attack modes, change Behavior Types (Cautious, Passive, Aggressive, etc.), Invoking damage on the AI, and a few other things.

    So, if anyone has any ideas for specific actions they know they will definitely need and will be using this, please let me know.
     
    BHS, hoodoo and unity_7UFP4-iCkwsgjg like this.
  19. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    @BHS I have a request for the next Emerald AI update. I'm writing Playmaker actions and one of the actions is SetStats, which allows me to set all the AI stat values in Playmaker. This will be useful if I want an AI to change mid battle. However, I see there is only an UpdateUINameText() function and nothing for the AITitle and AILevel . I want to be able to change those runtime and have the UI update accordingly. Can you add those Update functions in the next update?

    Thanks
     
  20. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    @BHS I have another request. Can we get a button in the animation setup Combat Movement section that lets us just copy the same animations from Non-Combat? A lot of models I have don't have special animations for combat movement and it would be nice to be able to set those up with a single click. Thanks.
     
  21. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    376
    Just stopping in to show the great progress with EAI, i deal with the slower aspect of EAI, and has worked out well, my post:

    New sound effects added (EmeraldAI/Animation Event), fog adjusted, need to tweak, but looking/sounding great!. My view in game (with player untagged):

     
    BHS and MagiSoftworks like this.
  22. raptorbastard

    raptorbastard

    Joined:
    Jan 31, 2019
    Posts:
    3
    Hey, can you help me in getting your asset to work with Malibers Animations Controller?
    https://assetstore.unity.com/packages/tools/animation/animal-controller-beta-148877
    Animal Controller or just one of the ones from his pack, I am trying to get the tiger to work with Emerald AI but as player. Controller works but I need to integrate it with Emerald AI so I can attack, be attacked, have allies etc :p.

    Thank you and amazing asset.

    EDIT:

    Using this controller from the tiger asset here:
    https://assetstore.unity.com/packages/3d/characters/animals/poly-art-tiger-75638

    Has attacks etc already working on click etc just need to make it send damage, recieve damage and ofc followers/enemies.
     
  23. MagiSoftworks

    MagiSoftworks

    Joined:
    Feb 12, 2019
    Posts:
    103
    Hey BHS! Know your busy but didn't know if you had and progress on Invector 3rd Person Damage Integration.

    I'm working though it but having trouble applying Particle Damage to EAI character. Seems like I have all straight but maybe I'm missing something.
     
    warthos3399 likes this.
  24. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    Did you add an EmeraldAttackEvent to your AI’s attack animation? This is required for your abilities to be created.
     
  25. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    My apologies for missing your posts, there’s a lot of them to keep track of. I’ve responded to your question with a solution. :)
     
  26. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    823
    @BHS is back! And with an update on making AI's sit in chairs :)
     
  27. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    I’ll look into this to see what’s happening. By sliding, do you mean the AI’s animations are never playing? Have you checked to make sure you’re not missing any movement animations? Does everything work correctly if the AI is not scaled down?
     
    FrostedBrain likes this.
  28. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    Quick update. I've implemented 14 Playmaker actions for Emerald AI and have just a few more to do before I'll get a beta package available for anyone to try.
     
  29. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    Yeah, I can update the UI API with the next update with the improvements you’ve suggested.
     
    magique likes this.
  30. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    Yeah, I’ll also add this to the next update as well. :)
     
    magique likes this.
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    I have one of Malibers assets so I can try to make a tutorial for it when I get the chance. Does it have its own health system? You could try using the Damage function on an Animation Event on the attack animations for triggering damage to AI.
     
  32. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    823
    @Malbers would probably give you one of the dragons if you ask him and tell him what you are using it for.
     
  33. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,676
    I'm on discord right now trying to help him. All you need is the Free Animal Controller, which has a sample wolf character and the controller. However, for some reason in Unity 2018, the Emerald AI is not attacking anything. I tried just a simple cube with the correct Tag that the AI is detecting for, but the AI just sits there and does nothing. My 2017 project with the same thing works fine. Trying to figure out what's wrong.

    [EDIT]
    Nevermind, I found out what was wrong. I didn't have the correct Player tag. Malbers uses Animal and it was set to Player.
     
  34. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    Hey there! I went through the integration tutorial and everything seems to be working correctly. What do you mean by particle damage? The integration tutorial should allow all weapons to damage an AI.
     
  35. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    I have one more minor update to release for Emerald AI before I release that updated. :)
     
  36. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    Yes, Emerald AI 2.3 should work fine with Invector.

    Are these particle effects fired from the player or the AI? If it's from the AI, everything should work correctly if you created the particle effect through an Emerald AI Ability Object. For a tutorial on this, see this link: https://docs.google.com/document/d/1DJ8sc96Q3DqANYkAwDhtR5JlmhkgrcLoD92bSA5FYdQ/edit

    If you are trying to fire the particle effect from the player, you will need to have some type of collision detection to cause damage to the AI impacted from the particle effect with something like the below. To use it, just attach it to the parent of the particle effect you would like to cause damage to an Emerald AI agent. You may need to adjust the size of the sphere collider's radius.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using EmeraldAI;
    5.  
    6. [RequireComponent(typeof(SphereCollider))]
    7. public class ParticleEffectDamage : MonoBehaviour
    8. {
    9.     public int DamageAmount = 10;
    10.     public string EmeraldAITag = "Emerald AI";
    11.  
    12.     private void Start()
    13.     {
    14.         GetComponent<SphereCollider>().isTrigger = true;
    15.     }
    16.  
    17.     void OnTriggerEnter(Collider other)
    18.     {
    19.         if (other.gameObject.CompareTag(EmeraldAITag))
    20.         {
    21.             if (other.GetComponent<EmeraldAISystem>() != null)
    22.             {
    23.                 other.GetComponent<EmeraldAISystem>().Damage(DamageAmount, EmeraldAISystem.TargetType.Player);
    24.             }
    25.         }
    26.     }
    27. }
     
  37. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    92
    Hi, question about ranged attacks, got them working in terms of the ai shooting at the player, however the ai shoots at the players feet. I adjusted the Player Offest Y Pos and still it shoots at the feet. I turned on the debug and I see it looking at the players feet. It might have a foot fetish, but I really would prefer it to shoot the player at least in the chest. Is there another setting im missing to adjust that offset?
     
  38. FrostedBrain

    FrostedBrain

    Joined:
    Sep 26, 2019
    Posts:
    13

    Everything works fine without the scaling applied
     
  39. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    376
    @Al- Sounds like a setting or animation problem between the different models. Things to check:
    • Check the animation (play it too) and any animation settings (not looped), EAI doesnt support Legacy.
    • Check or adjust "seconds to disable", default is 6.
    • Check the health/re-gen health settings.
    • Make sure "death type" is correct.
    Other than that, ive never had a death animation fail. And i use EAI on alot of different models (biped/quadraped/humanoid/custom), again not 1 has failed. It will happen now that i said that, lol
     
    Last edited: Oct 24, 2019
    Al- likes this.
  40. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    376
    I use EAI daily, and always trying different things working on concepts. Check this out, a new carnivorus plant. this thing appears from out of the ground, attack/spit poison, disappear underground, then moves towards you underground before re-appearing, lol (WIP needs animation speed adjustment, hes too fast) was a challenge getting it to work correctly, EAI came through on this one :)

     
    Neviah, BHS and MagiSoftworks like this.
  41. Al-

    Al-

    Joined:
    Jun 5, 2015
    Posts:
    24
    Thanks a lot for the help!. I found the error in one of my scripts that I added to Emeraldaisystem. Emerald AI was working great, -as usually :)
     
  42. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    376
    Nice, glad it worked out, yea, script errors rears their ugly head, lol
     
    Last edited: Oct 24, 2019
    Al- likes this.
  43. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    When you enable the Debug Log options, is the AI targeting the right object (not just the visual line)? The height in which the AI fires is based off of half player's collider's height so it should always hit the center of its collider. Sometimes what happens is the AI targets the wrong object which is why it fires too high or low.
     
  44. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    I tested this out and everything is working correctly with the AI I'm testing, even with a 75% reduced scale. Are you using Root Motion or NavMesh Driven for your Movement Type?
     
  45. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    223
    Is there a list of all the event names we could be using, this would make ti easier for the future.

    I think there is a bug.

    The projectile now spawns, if i remain within range it will continue to pool under Emerald Object Pool. Only the 1 projectile object.

    However, when I move out of dodge and get the NPC to melee attack or chase me, it no longer pools the object. I have tried manually activating the obj but it does not activate either.

    There are other times when I get it to spawn 2 projectiles when I am too close and get hit, however the same buggy thing happens when the animations and all are playing out but no longer pools the projectile.

    Whats causing this or is it a bug, whats the fix?

    Thanks
     
  46. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    92
    I'll take a look at exactly what the AI is targeting tonight, maybe its getting something else on the player. Its def the player as the scene only has a floor, ai and player but I do use invector so maybe its targeting the footsteps or something.

    Side note, its is funny, its like the ai is warning the player by shooting at its feet, cause when I get close the ai does not play, melee works quite well.

    One question since you mentioned the ai targets the middle of the collider, is there a way to Incorporated like head shots. I'm at work so I can't see the docs, but would be cool if you could create abilities that use different target tags/layers. So I could make a head shot tag/layer and give it say a 15% chance success. But that may already be in so I will check the docs when I get home.
     
  47. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    92
    Hi, so the ai is targeting the player, but continues to shoot at the foot. I thought maybe the head look script used with invector was causing it, as it creates a sphere collider around the player with a player tag, however with that disabled the ai still shoots at feet.

    I tested two ai and they work as expected, but the ai against player remains the same. Im kind of stumped at the moment.
     
  48. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    A list of all events can be found under AI’s Settings>Events.

    A list of all usable API, which can be used programmatically or through events, can be found here: https://docs.google.com/document/d/1ns8m7Ol_gaKeYJ3YbaRjDy09xG98UoIXKCaWLGJeg74

    The pool should expand as needed per object. Once the object has been despawned, the previously spawned objects will be used before new ones are created. The only thing that can disrupt this process is if there is a component on the projectile that isn’t supposed to be there, such as a despawn object script (these were used previously, but are now despawned differently).

    I will look into this, but ensure that there are no extra components on your projectiles. There only thing that’s needed is the particle itself. Emerald AI handles everything else.
     
  49. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,045
    I will look into this to see if I can pinpoint what’s happening. As for the AI aiming for headshots, I can add a feature like this when I add location based damage support. For now, you could fake it by generating odds when applying damage and multiplying damage if the odds fell within the 15% range.
     
    SickaGamer likes this.
  50. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    92
    Cool, so I tested a few projects and the AI still shoots at the players feet. I have Unity Version 2018.4.11f1 and the newest versions of this asset and invector shooter asset. I'm pretty sure invector is the issue as the demo player gets the same reaction.

    I created a work around where I added a empty object to my player, gave it a collider and created a new tag and layer for it. I set it to trigger and had the AI reference those. I then updated the emeraldPlayerDamage script to look for the transform.root which gets the main player to call damage.

    I works fine enough for me until maybe you can find out a better way to do it.