Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] Emerald AI 2.4.1 - The Ultimate Universal AAA Quality AI Solution

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

  1. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    I can Submit a copy of the project to him, or share it to you guys if he wants .unless he gives me the go I can't.
     
  2. ChoChick

    ChoChick

    Joined:
    Jul 18, 2016
    Posts:
    39
    I am creating a battle between Aggressive Brave AI and Cautious Coward AI.
    When CautiousAI is driven into the corner and cannot escape, AggressiveAI has a problem that it stops on the spot without attacking even if CombatState is Active.

    [Aggressive AI settings]
    StoppingDistance 0.5
    AttackDistance 1.5
    AttackHeight 0.5
    BackupType Instant
    Backup Seconds 1-2

    Are there any other settings I should check?
     
  3. Syllvia

    Syllvia

    Joined:
    Mar 26, 2013
    Posts:
    16
    @Rahd
    Howdy! I'm curious, while you're already in there mucking around in the code, do you have any advice on how to configure emerald AI to have a kind of taunt system? Such as [ do attack, shuffle back, then decide to do another attack or do a taunt] or to generally just code the ai to waste some time? My biggest issue with Emerald is that it can't strafe, which makes stuff like a normal "attack player, shuffle left and right a bit then attack again" kind of idle behavior impossible. It just needs something more than just standing still or blocking and my immediate tests to circumvent it didn't really work out.

    the need for that kind of beat'em'up/dynasty warrior/geeneral dungeon crawling sorta downtime movement is the reason i'm prob not gonna use emerald for an upcoming project and just code something myself, but a tool or insight into how that might get added in would be rad. I know how to code AI.

    Emerald does most of what i'd need my AI system to do, but not being able to circle the player during downtime is kind of a dealbreaker.
     
    Last edited: Jun 24, 2020
    Rahd likes this.
  4. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    Total Aggro hits and Aggro action i think .



    Good suggestion !! taunt!!.

    Really working on something just like that, dodge when aimed or attacked (roll or strafe).

    Right now I'm adding Damage/defense elements like Fire, Cold, Toxic... and Debuffs like stun bleed freeze SetOnFire
    and
    I'm trying to make the AI Attacks and movements work with Stamina or mana, when the stamina runs out the Ai will switch from run to Walk when chasing, when attacking it will play idle_tired or charge animation. in the Idle State.

    This asset is good, but did not find any other asset that has those features, or at least better than Emerald.


    However, you can start adding those when calling the Backup State, since this is the place that you can do such behavior. I think the Behavior script checks after every attack (AggressiveBehavior)if the player is too close (CalculateBackupState(); )then if the backup condition is met (Instant , Odds and !BackupDelayActive) then it will backup( BackupState(); ).

    there along with BlockState, you can add the taunt state.
    you just add new animation states for the strafe or roll, and when you set a destination make it a Random.insideUnitCircle with a bigger radius of the player position for a duration.
    the dev really left this place of code open for any Behavior between attacks.

    You can use a copy of CalculateBackupState as a good start example, things like ResetTrigger("Hit");ResetTrigger("Attack"); are needed i think . SetBool("Walk Backwards", true); can be replaced with your roll animation parameter.
    and the Raycast Behind can now be a raycast into the direction of the roll or strafe position (Random.insideUnitCircle of the player ). and change the BackupDelayActive to taunt or roll or strafe Delay so that the Ai won't do the same behavior over and over.

    As for the shuffle back, it's the same as BackupState just faster animation like a sudden jump back and faster Agent Speed.

    I think the dev did not add this because most game devs won't even bother to add such a system, it needs too many animations and work.


    Great that you brought it up !!, That's my main issue right now, the Ai just keep rushing the player, not giving him a chance to even attack. Emerald is a very hard Ai to fight, but players want to have fun. so the Ai needs to be a little stupid. maybe by next week or 2, I will have the full state and how to add it.


    ,
     
    Last edited: Jun 24, 2020
  5. ChoChick

    ChoChick

    Joined:
    Jul 18, 2016
    Posts:
    39
    I don't know the cause, but it seems that the problem was solved while changing the value of Inspector.
    thank you for the advice.
     
  6. Nitrox32

    Nitrox32

    Joined:
    May 9, 2017
    Posts:
    136
    Can someone tell me why this is happening? Ranged weapons do not work with Invector characters. Melee weapons are fine. I have gone through the ranged ai tutorials over and over and gotten the same result. With a Pick Target of Method of First Detected the ai over shoots. If I adjust the Player Offset Y position to a lower value so my player gets hit. No damage gets applied to my player. When I change the Pick Target Method to Closet I have to really get close for the ai to engage and when it does it only fires at my feet. In this case damage is applied.
     
  7. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    check the attack Height ? under damage settings
     
  8. Nitrox32

    Nitrox32

    Joined:
    May 9, 2017
    Posts:
    136
    This is what I found regarding the AI shooting at the Invector characters head(or feet). This happens when Invector's head track system is turned on. This was the solution post by Darrkbeast:

    "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."

    The only thing I need would be the code. Any idea what how to apply what he's talking about?
     
  9. Nitrox32

    Nitrox32

    Joined:
    May 9, 2017
    Posts:
    136
    OK, it appears the solution is to turn off the vHeadTrack script on the Invector player.

    So the bottom line is, in order to get the Emerald AI ranged attack to work with Invector using the First Detected setting in the Pick Object Type method, three things need to happen.

    1) Apply the code change that you gave me on Discord. That fixed the two errors I was getting in the video above. I guess that will be fixed in a future update.
    2) Add a dummy object object as a child to the Invector character and set its layer to Player and disable its mesh renderer.
    3) Deactivate (or remove) the Head track component on the Invector character.

    All of this stemmed from me not being able to get Kripto effects to work with Emerald. Once these issues were taken care of, creating an ability object with one of the Krpito effects worked like charm. Thanks for your help!
     
    Last edited: Jun 27, 2020
    Rahd likes this.
  10. MintsTV

    MintsTV

    Joined:
    Feb 12, 2019
    Posts:
    1
    Is there anyway to have the enemy detection distance be based on distance within the current navmesh as opposed to general position distance? Can't seem to find a way to do this in a maze-like layout.

    Also seem to be having an issue where after attacking enemies fine my damage will become negative randomly without ever making a change to the value.
     
    Last edited: Jun 28, 2020
  11. MilesSmiles

    MilesSmiles

    Joined:
    Nov 27, 2012
    Posts:
    115
    Hi there,

    Just purchased Emerald. I have everything setup on an AI enemy but he's not detecting my player. AI will walk around but he doesnt see me.

    Here's a screenshot of the AI. And my player has the tag of "Player" and the layer of "Character".

    Thanks,
    Shane
     

    Attached Files:

  12. syphon1977

    syphon1977

    Joined:
    Apr 18, 2019
    Posts:
    14
    I got Game Kit Controller and Emerald working together, except when I kill an AI enemy I do not receive any XP, currency, etc. There is an "On Death Event ()" in the Emerald AI System script, but I am not sure what to put in there.
     
  13. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,004
    The GKC dev should tell you
     
  14. syphon1977

    syphon1977

    Joined:
    Apr 18, 2019
    Posts:
    14
    The GKC dev helped me figure it out. For those of you wondering how to get loot from killing an Emerald AI when using Game Kit Controller:

    1. Add the Object Experience System component to your Emerald AI (Boar Grey)
    2. Drag the Emerald AI into the On Death Event
    3. Select objectExperienceSystem --> sendExperienceToPlay (GameObject)
    4. Drag the Player Controller into the GameObject field
    upload_2020-7-1_17-29-21.png
     
    Fibonaccov and Rahd like this.
  15. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    31
    Hello, I have a question about walk cycles. I have a frog creature that uses a hopping animation for it's locomotion but because of the way movement is currently handled, if the entity stops before the animation finishes, it snaps back to it's zero location. Is there a way to force an entity to move in set distances (like 4 meters at a time) or to ensure it runs until the animation is completed? Thanks in advance!
     
  16. NenoSun

    NenoSun

    Joined:
    Jun 1, 2017
    Posts:
    1
    Hello. I've got everything set up according to the tutorial of the wiki page on Github But my character cannot deal any damage.
    I created two characters. They both only had melee attacks. I turned on all the UI components. And I started to play the scene.
    No error message was prompted in the console. All animations worked pretty well. I could see the damaging number UI like "-4", "-5" popping up upon the head of the chararcters, but the health bar just did not move. Those two characters kept on attacking each other but with no damage delt and consequentially no character dies.

    Could you help me fix this problem? Many Thanks.
     
  17. Mythran

    Mythran

    Joined:
    Feb 26, 2013
    Posts:
    48
    Hello, i'm currently having a doubt related with events, is it possible to change the Wander type at runtime with events?
    Thanks
     
  18. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    353
    On Unity 2018.4.18 using Emerald AI 2.4.0.1
    I created two AIs (generic anims, companion type, wander type NavMesh) and all worked fine but I then added another three with the same settings, same tag, same layer (although each using their own animations and animation controllers) and they get moved to the world origin on Play. It's not where they're placed in the scene. They then all seem stuck there, on top of each other (there's no walkable navmesh at that spot, it's inside a building) with their idle animations playing.

    Is there anything stupid I might have done wrong?
     
  19. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    Some Of the mess I have Added :p


    upload_2020-7-5_4-5-42.png
    upload_2020-7-5_4-7-29.png

    upload_2020-7-5_4-8-30.png
    upload_2020-7-5_4-6-14.png
    upload_2020-7-5_4-10-30.png
     
    Last edited: Jul 5, 2020
    HeadClot88 and AdminArdagor like this.
  20. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    I think you want to use root motion driven Ai or use Inplace Clips
    the Ai should do that already, do you have your clips set on loop time?
    -4 -5 I think the damage is set to negative ?? or health is negative ... try to debug log the health and the damage amount inside the System script( not the editor one).
    -4 ,-5 should show only when the player gets attacked from the examples ...
    Code (CSharp):
    1.  if (AIAgentActive && CombatStateRef == CombatState.NotActive && !DeathDelayActive && BehaviorRef != CurrentBehavior.Companion && BehaviorRef != CurrentBehavior.Pet)
    2.                 {                                    
    3.                     Wander();
    4.                 }
    so changing the CombatStateRef to CombatState.NotActive and CurrentBehavior to passive should do that .
    check the agent layer mask? it should include the walkable layer ... not sure
     
  21. C_Occlusion

    C_Occlusion

    Joined:
    Jun 4, 2012
    Posts:
    43
    Does Emerald AI work with Opsive Ultimate FPS 2+
     
  22. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    353
    @Rahd I'm stumped too. Went through all the settings and just can't see any difference. Is there (or could you add) some kind of debugging mode that would help narrow down where things are going wrong?
     
  23. AdminArdagor

    AdminArdagor

    Joined:
    Feb 6, 2018
    Posts:
    40
    Rahd : could you make an instruction how to add a dodges to an Emerald ?

    I would be very grateful.
     
  24. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    inside the Damage Fonction you can find it in the EmeraldAiSystem
    you will find this line :
    CurrentHealth -= DamageReceived;
    you just have to add :
    Debug.Log (CurrentHealth );
    Debug.Log (DamageReceived);
    you can add Debug.Log (Damage); at the start to see if the damage when not affected by any conditions like block

    Hi it's a long process but here is the short version :
    in the Behaviors script like i said last time I added DodgeState ();
    using those parameters :

    Code (CSharp):
    1. if (  EnemyNPCComponent.UseDodging == EnemyNPCAISystem.YesOrNo.Yes && (  !(EnemyNPCComponent.CurrentHealingState== EnemyNPCAISystem.HealingState.Refill_Animation) && !(EnemyNPCComponent.CurrentStaminaRestoreState == EnemyNPCAISystem.StaminaRestoreState.Refill_Animation)    )  &&    EnemyNPCComponent.CurrentBlockingState == EnemyNPCAISystem.BlockingState.NotBlocking &&     EnemyNPCComponent.CurrentCirclingState == EnemyNPCAISystem.CirclingState.NotCircling   && EnemyNPCComponent.CurrentTeleportState == EnemyNPCAISystem.TeleportState.NotTeleport   )
    2.                 {
    3.  
    4.                     if (!DodgeDelayStart) {
    5.                         DodgeState ();
    6.                     }
    7.                 }

    the State IS :

    Code (CSharp):
    1. public void DodgeState()
    2.         {
    3.      
    4.             if (!EnemyNPCComponent.BackingUp && !EnemyNPCComponent.IsMoving && EnemyNPCComponent.CurrentTarget && !EnemyNPCComponent.DeathDelayActive)
    5.             {
    6.  
    7.  
    8.  
    9.  
    10.                 bool AnimationCondition = false;
    11.                 if (EnemyNPCComponent.DodgeAnimTriggerType == EnemyNPCAISystem.Dodge_Cicle_Teleport_TriggerType.Trigger_on_Idle_only){
    12.  
    13.                     AnimationCondition = (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation || EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation1|| EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation2 );
    14.  
    15.  
    16.                 }else if (EnemyNPCComponent.DodgeAnimTriggerType == EnemyNPCAISystem.Dodge_Cicle_Teleport_TriggerType.Trigger_on_Idle_GetHit){
    17.  
    18.                     AnimationCondition = ((EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation || EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation1|| EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatIdleAnimation2 )|| (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit1Animation  ) || (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit2Animation  )|| (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit3Animation  )|| (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit4Animation  )|| (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit5Animation  )|| (EnemyNPCComponent.CurrentAnimationClip == EnemyNPCComponent.CombatHit6Animation  ) );
    19.                     EnemyNPCComponent.AIAnimator.ResetTrigger("Hit");
    20.                     EnemyNPCComponent.GettingHit = false;
    21.                 }
    22.  
    23.  
    24.  
    25.                 if (EnemyNPCComponent.CombatStateRef == EnemyNPCAISystem.CombatState.Active && !EnemyNPCComponent.Attacking && !EnemyNPCComponent.GettingHit && EnemyNPCComponent.AIAgentActive &&
    26.                     EnemyNPCComponent.m_NavMeshAgent.remainingDistance <= EnemyNPCComponent.m_NavMeshAgent.stoppingDistance && !EnemyNPCComponent.m_NavMeshAgent.pathPending && !EnemyNPCComponent.AIAnimator.GetBool("Attack"))
    27.                 {
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34.                     if ( ((EnemyNPCComponent.DodgeTypeRef == EnemyNPCAISystem.DodgeType.Attacked&& EnemyNPCComponent.WasAttacked ) || (   EnemyNPCComponent.GeneratedDodgeOdds <= EnemyNPCComponent.DodgeOdds && EnemyNPCComponent.DodgeTypeRef== EnemyNPCAISystem.DodgeType.Odds   ) ||((   EnemyNPCComponent.GeneratedDodgeOdds <= EnemyNPCComponent.DodgeOdds && EnemyNPCComponent.DodgeTypeRef== EnemyNPCAISystem.DodgeType.Attacked_WithOdds && EnemyNPCComponent.WasAttacked  ) )   )                 && (EnemyNPCComponent.AttackTimer < EnemyNPCComponent.AttackSpeed - 0.25f &&AnimationCondition && EnemyNPCComponent.CurrentBlockingState == EnemyNPCAISystem.BlockingState.NotBlocking && (  !(EnemyNPCComponent.CurrentHealingState== EnemyNPCAISystem.HealingState.Refill_Animation) && !(EnemyNPCComponent.CurrentStaminaRestoreState == EnemyNPCAISystem.StaminaRestoreState.Refill_Animation)    )&&     EnemyNPCComponent.CurrentCirclingState == EnemyNPCAISystem.CirclingState.NotCircling &&EnemyNPCComponent.CurrentDodgeState == EnemyNPCAISystem.DodgeState.NotDodge && EnemyNPCComponent.CurrentTeleportState == EnemyNPCAISystem.TeleportState.NotTeleport))
    35.  
    36.                     {
    37.                         EnemyNPCComponent.AIAnimator.ResetTrigger("Attack");
    38.                         EnemyNPCComponent.CurrentDodgeState = EnemyNPCAISystem.DodgeState.Dodge;
    39.  
    40.                         if (!EnemyNPCComponent.isDodge) {
    41.                             EnemyNPCComponent.AIAnimator.SetBool("Dodge", true);
    42.                             EnemyNPCComponent.isDodge = true;
    43.                      
    44.  
    45.                             Vector3 direction =Vector3.zero;
    46.                             if (EnemyNPCComponent.UseDodgingBack== EnemyNPCAISystem.YesOrNo.Yes && EnemyNPCComponent.UseDodgingLeftRight== EnemyNPCAISystem.YesOrNo.Yes) {
    47.  
    48.                                 int Randomdirection = Random.Range (0, 3);
    49.  
    50.  
    51.  
    52.                                 switch (Randomdirection) {
    53.  
    54.                                 case 0:
    55.                                     direction = (EnemyNPCComponent.CurrentTarget.position - transform.position).normalized;
    56.                                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeBack", true);
    57.                                     break;
    58.  
    59.                                 case 1:
    60.                                     direction = (Vector3.right - EnemyNPCComponent.CurrentTarget.position).normalized;
    61.                                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeLeft", true);
    62.                                     break;
    63.  
    64.                                 case 2:
    65.                                  
    66.                                     direction = (Vector3.left - EnemyNPCComponent.CurrentTarget.position).normalized;
    67.                                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeRight", true);
    68.                                     break;
    69.  
    70.  
    71.  
    72.  
    73.  
    74.  
    75.                                 }
    76.  
    77.  
    78.  
    79.                             } else if (EnemyNPCComponent.UseDodgingBack== EnemyNPCAISystem.YesOrNo.No && EnemyNPCComponent.UseDodgingLeftRight== EnemyNPCAISystem.YesOrNo.Yes) {
    80.  
    81.                                 int Randomdirection = Random.Range (0, 2);
    82.  
    83.  
    84.  
    85.                                 switch (Randomdirection) {
    86.  
    87.                              
    88.  
    89.                                 case 0:
    90.                                     direction = (Vector3.right - EnemyNPCComponent.CurrentTarget.position).normalized;
    91.                                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeLeft", true);
    92.                                     break;
    93.  
    94.                                 case 1:
    95.                                     direction = (Vector3.left - EnemyNPCComponent.CurrentTarget.position).normalized;
    96.                                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeRight", true);
    97.                                     break;
    98.  
    99.  
    100.  
    101.  
    102.  
    103.  
    104.                                 }
    105.  
    106.  
    107.                             }
    108.                             else if (EnemyNPCComponent.UseDodgingBack== EnemyNPCAISystem.YesOrNo.Yes && EnemyNPCComponent.UseDodgingLeftRight== EnemyNPCAISystem.YesOrNo.No) {
    109.  
    110.  
    111.                                 direction = (EnemyNPCComponent.CurrentTarget.position - transform.position).normalized;
    112.                                 EnemyNPCComponent.AIAnimator.SetBool ("DodgeBack", true);
    113.                      
    114.  
    115.                              
    116.  
    117.  
    118.                             }
    119.                      
    120.                      
    121.  
    122.                             Vector3 GeneratedDestination = transform.position + -direction * EnemyNPCComponent.DodgeDistance;
    123.                             GeneratedDestination.y = transform.position.y;
    124.                             EnemyNPCComponent.m_NavMeshAgent.destination = GeneratedDestination;
    125.  
    126.  
    127.  
    128.                         }
    129.                     }
    130.  
    131.  
    132.  
    133.  
    134.                 }
    135.             }
    136.  
    137.  
    138.  
    139.  
    140.  
    141.             if (EnemyNPCComponent.CurrentDodgeState == EnemyNPCAISystem.DodgeState.Dodge)
    142.             {
    143.                 DodgeTimer += Time.deltaTime;
    144.  
    145.          
    146.                 if (DodgeTimer >= EnemyNPCComponent.DodgeTime || EnemyNPCComponent.BackingUp) {
    147.                     EnemyNPCComponent.CurrentDodgeState = EnemyNPCAISystem.DodgeState.NotDodge;
    148.                  
    149.                     EnemyNPCComponent.AIAnimator.SetBool ("Dodge",false);
    150.                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeBack", false);
    151.                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeLeft", false);
    152.                     EnemyNPCComponent.AIAnimator.SetBool ("DodgeRight", false);
    153.                     EnemyNPCComponent.isDodge = false;
    154.                     if (DodgeTimer >= EnemyNPCComponent.DodgeTime) {
    155.                         EnemyNPCComponent.AIAnimator.SetBool("Dodge Cooldown Active", true);
    156.                         Invoke ("ActivateDodgeCooldown", 0.75f);
    157.                         DodgeTimer = 0;
    158.                         DodgeDelayStart = true;
    159.              
    160.                     }
    161.                 }
    162.             }
    163.  
    164.         }
    .
    I know that a mess of code but that the best I can do.
    you will notice that there is a lot of things like CurrentTeleportState, CurrentCirclingState .. etc those are States that works like dodge, but all of the States are like the Blocking State so copying that could be a great Start
    try to remove those TeleportState CirclingState ... and just focus on Dodge
    you will have to add to the animator other states it the bool parameters like Dodge DodgeBack DodgeLeft DodgeRight ...

    I wish i could share it all but I have modified most of the scripts to make this work even the AnimatorGen Script, And I really doubt that The Original Dev Wants His Work shared on a public forum. I'm Still Trying To fix Some Bugs, If @BHS Wants I would Be glad To Work with him To add The Jump, Dodge, Teleport, Stamina, Circling, Tired, Healing Animation, ... etc For the next update. I will Make a Video Explaining the Changes I have made , here is a small Video : (I run out of Animation Clips So I just used Walk Left Walk Right for Dodge Animations)
     
    Fibonaccov and LVelior like this.
  25. AdminArdagor

    AdminArdagor

    Joined:
    Feb 6, 2018
    Posts:
    40
    Rahd : Thank you very much ! I will try to implement.
     
    Rahd likes this.
  26. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    284
    Ran into a major problem regarding line of sight of an AI. It seems it will only react to detecting a player who's collider is at eye-level for the AI. So if your player character can e.g crouch, the AI will just walk straight past as though nothing is there.
     
  27. OJDee

    OJDee

    Joined:
    Feb 11, 2014
    Posts:
    52
    Just got the asset and seems pretty comprehensive. I have two questions:

    1. I have a cautious cowardly AI that is set to flee from player when detected. This seems to work for the most part with the AI running away, but sometimes the occasional AI will just ignore player's presence, despite getting right next to it. This is on a flat plane with detection set to Trigger (There are no other objects in the scene). Any idea what might cause this?

    2. I would like to be able to introduce fleeing based on a programmatic value of 'noise' ie the player can be making different noise levels based on vehicle / on foot etc. Looking at the API I see I can change the behaviour, confidence etc.. but wondered what the advised way to achieve this effect would be. Ideally it would be a FleeFrom(Transform player) function that I can call on qualifying AI objects based on noise radius for example. Anyone suggest the best way to achieve such control?

    Thanks
     
  28. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    698
    How do I determine what version of Emerald is in my project?

    and

    What is the recommended update procedure?
     
  29. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    If your player's collider's size is modified, you should use a dummy object in its place. This would be an object with a collider with your player tag and player layer that's attached to your player so your actual player won't use said tag and layer, if that all makes sense.
     
  30. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    1. I'm not sure why it wouldn't work. I tested an Cowardly AI and was not able to recreate this. Have you double checked your tags and layers? Also, check to make sure there are no additional colliders on your AI that could be interfering with the detection process.

    2. I just added API to allow AI to flee from the specified target to the 2.4.1 update. It should be live within the next few days.
     
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    I really wish Unity had a system in place for this. Can you please provide a screenshot of an AI's attacks list? This will give me a good idea of what version you are using.
     
  32. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    Hey everyone!

    Emerald AI 2.4.1 has been submitted and is awaiting approval. I call this update the Quality of Life Update. It addresses all of the bugs users have been having, adds tons of new features to decrease the amount of time it takes to create an AI, and adds some much needed API. This update also replaces AI Name, Title, and Level UI with Unity's UI system instead of using the Text Mesh system which allows for more features and cleaner looking text (There shouldn't be anything users have to do on their end). All of the new features, improvements, and bug fixes are detailed below.

    This is just one update of many updates to help Emerald AI be the most solid and dependable AI system out there. If you have any requests for future updates or improvements, feel free to let me know.

    Features
    • Redid the AI's Name UI using Unity's UI system instead of the TextMesh system. This allows for further control and more customization.
    • Redid the AI's Level UI using Unity's UI system instead of the TextMesh system. This allows for further control and more customization.
    • Emerald AI's built-in UI system now supports Rich Text so users can utilize Unity's Markup Format system such as <size=6><color=yellow>AI's Title</color></size> or <b>AI's Name</b> right from within the Emerald AI Editor. This also allows an AI title to be a different color than their name.
    • A button has been added to the Emerald AI Editor to copy an AI's non-combat movement animations to their combat movement animations, given that they use the same animations, to avoid having to manually reapply the same animations.
    • A button has been added to the Emerald AI Editor to check for any needed missing animations, while in the Unity Editor, and debug all missing animations to the Unity Console.
    • A button has been added to the Emerald AI Editor to take users to a tutorial for creating and using Attack Sounds. Since they are done through Animation Events, this often lead to confusion on how they were created. Clarification has also been added that Attack Sounds use Animation Events and do not automatically play.
    • A button has been added to the Emerald AI Editor to take users to a tutorial for creating and using Death Sounds (When using death animations). Since they are done through Animation Events, this often lead to confusion on how they were created. Clarification has also been added that Death Sounds (When using death animation) use Animation Events and do not automatically play.
    • A button has been added to the Emerald AI Editor to take users to a tutorial for creating and using Warning Sounds (When using the proper Behavior and Confidence Types). Since they are done through Animation Events, this often lead to confusion on how they were created. Clarification has also been added that Warning Sounds (When using the proper Behavior and Confidence Types) use Animation Events and do not automatically play.
    • Added an Attack Impact Effect to the Melee Attacks List so users no longer have to add one via OnAttackEvents. This allows each melee attack to have its own impact effect that plays at its target's location. If no effect is applied, this feature will be ignored. This feature is different to that of the effects within Hit Effect section.
    • Added an option within the UI tab to control the position of the AI's Level UI.
    • Added an option within the UI tab to control whether or not an AI's Name will use an outline effect.
    • Added an option within the UI tab to control whether or not an AI's Level will use an outline effect.
    • Added an option within the UI tab to control the Name UI's Outline Size.
    • Added an option within the UI tab to control the Name UI's Outline Color.
    • Added an option within the UI tab to control the Name UI's Font.
    • Added an option within the UI tab to control the Level UI's Outline Size.
    • Added an option within the UI tab to control the Level UI's Outline Color.
    • Added an option within the UI tab to control the Level UI's Font.
    • Added an option within the UI tab to control the line spacing between an AI's Name and Title.
    • Added an option within the UI tab to control the max size the UI will be scaled when a player is getting further away from an AI's UI.
    • Added an option to the Combat Text Manager that controls the target types that will be affected by the Combat Text System. This includes options to have the combat text only be displayed on AI (including non-AI targets), only on Players, or be displayed on both AI and players (the default setting).
    • Added an option to control the overall height of the text for the Combat Text System within the Combat Text Manager.
    • Increased the Combat Text Manager's Font Size cap to 50, up from 30.
    • Added full support of obstruction detection to the Debug Tools for melee attacks.
    • Added an AI's current target's Target Type to be displayed when using the Debug Log Targets option when using the Debug Log Tools.
    • Added an option within the Debugging Tools for projectiles to Debug Log the object they collided with to the Unity Console. This should help users who are unsure as to why an AI's projectile is not hitting their target. This is often a hidden collider on the player. Using this option will make this easier to identify.
    • Added a button to the Detection Options to automatically find an AI's head transform so users don't have to manually search through their AI for it. The effectiveness of this is largely dependent on how well the developer of the model named a model's transforms.
    • Added an option to adjust the overall text height to the Combat Text Manager.
    • Added an OnHealEvent to Emerald AI's Event tab that is called when an AI cast a healing ability.
    • Added an OnCtricalHitEvent to Emerald AI's Event than that is called when an AI successfully lands a critical hit.
    • Added Critical Hits Sound List to the Sounds tab. Critical hit sounds will play when an AI successfully lands a critical hit when using the Melee Weapon Type. This feature can be disabled by simply leaving the Critical Hits Sounds List empty.
    • Moved the Hit Transform setting from AI's Settings>Combat>Combat Actions to the Detection Options as it's often missed and is more apart of the detection process.

    Bug Fixes
    • Fixed an issue where Emerald AI would through incorrect "Missing Death Animation" warning message.
    • Fixed an issue with the First Detected option when using the Line of Sight Detection Type that would not properly detect the target.
    • Fixed an issue that resulted in the AI getting stuck at a speed of 0.05 when generating a destination to enclosed areas such as a room.
    • Fixed an issue that would allow an AI using non-Root Motion animations to sometimes briefly move while playing stationary attack animations.
    • Fixed an issue that stopped a Cautious non-Coward AI from being reverting to its original behavior after turning aggressive.
    • Fixed an issue that would make an AI skip the next ordered attack animation when using the Order Pick Type while using a min and max Attack Speed of 0.
    • Fixed an issue that would sometimes cause AI using Root Motion to stutter when arriving to their destinations.
    • Fixed some scripts that had inconsistent line endings messages.
    • Fixed a bug that caused run attacks to generate damage from stationary attacks.
    • Fixed an issue that would make make run attacks aim towards an incorrect destination, when using Root Motion.
    • Smoothed out transition of AI using Root Motion when transitioning between idling and moving animations.
    • Updated Ability Object editor so it properly serializes to allow undo and redo to work. This also allows changes to mark the scene as dirty, which could have lead to changes not being saved to Ability Objects.
    • Made the new default Behavior Type Aggressive when setting up a new AI since most users use this setting. This will help make things easier for newer users in case it's missed.
    • Added a warning message to the Emerald AI Editor to create a Melee Run Attack if it's enabled and the Melee Run Attack List is empty.
    • When Debugging Tools are enabled, all options are enabled by default (To Clarify, this does not affect AI who do not have Debugging Tools enabled).
    • Added full support of obstruction detection to melee attacks. This mostly worked prior to the this version, however, some users would run into issues with open and closeable doors.
    • Reduced capped Attack Distance from 1.5 to 0.5 within the Emerald AI Editor as some users were needing this value to be lower.
    • Improved use of turning animations when wandering.
    • Improved the Combat Text System's Animation Types' movements so they work with a wider range of camera angles/types.
    • Base Combat Text height is now based off of an AI's Hit Transform.

    New API
    • Added UpdateHealth(int MaxHealth, int CurrentHealth) to EmeraldAIEventsManager to update the AI's Max Health, Current Health, and health bar, if it's enabled
    • Added SearchForClosestTarget() to EmeraldAIEventsManager to search for a new target that's closest to the AI within an its detection radius.
    • Added SearchForRandomTarget() to EmeraldAIEventsManager to search for a new random target that's within an AI's detection radius.
    • Added FleeFromTarget(Transform FleeTarget) to EmeraldAIEventsManager to allow an AI to flee from the specified target.
    • Added UpdateAIMeleeDamage(int MeleeAttackNumber, int MinDamage, int MaxDamage) to EmeraldAIEventsManager to update an AI's melee attack damage.
    • Added UpdateAIAttackSpeed (int MinAttackSpeed, int MaxAttackSpeed) to EmeraldAIEventsManager to update an AI's attack speed.
    • (A much needed feature) Added RotateAITowardsTarget(Transform Target, int Duration) to EmeraldAIEventsManager to allow AI to stop what they are doing and rotate to the specified Target parameter for the length of the Duration parameter. If a Duration of -1 is used, the length will be indefinite and can be canceled with CancelRotateAITowardsTarget().
    • Added RotateAITowardsPosition(Vector3 TargetPosition, int Duration) to EmeraldAIEventsManager. An alternative to RotateAITowardsTarget if for some reason a Transform can't be used. If a Duration of -1 is used, the length will be indefinite and can be canceled with CancelRotateAITowardsPosition().
    • Added CancelRotateAITowardsTarget() to EmeraldAIEventsManager to cancel RotateAITowardsTarget as explained above.
    • Added CancelRotateAITowardsPosition() to EmeraldAIEventsManager to cancel RotateAITowardsPosition as explained above.
    • Added RotateAIAwayFromTarget(Transform Target, int Duration) to EmeraldAIEventsManager to allow AI to stop what they are doing and rotate away from the specified Target parameter for the length of the Duration parameter. If a Duration of -1 is used, the length will be indefinite and can be canceled with CancelRotateAIAwayFromTarget().
    • Added RotateAIAwayFromPosition(Vector3 TargetPosition, int Duration) to EmeraldAIEventsManager. An alternative to RotateAIAwayFromTarget if for some reason a Transform can't be used. If a Duration of -1 is used, the length will be indefinite and can be canceled with CancelRotateAIAwayFromPosition().
    • Added CancelRotateAIAwayFromTarget() to EmeraldAIEventsManager to cancel RotateAIAwayFromTarget as explained above.
    • Added CancelRotateAIAwayFromPosition() to EmeraldAIEventsManager to cancel RotateAIAwayFromPosition as explained above.
     
    Last edited: Jul 23, 2020
    julianr, Akshara, Rahd and 2 others like this.
  33. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    284
    The thing is though, the player's collider needs to be decreased in size for him to be able to hide behind objects in the scene - this is when it's actually desirable for the AI not to see them. However, the AI should still see the player if they crouch out in the open - even if the player's collider size is now smaller.

    The only way to fix this currently is to assign a dummy object to be used as the AI's head transform that's lower down than it's "real" head. But by doing this, you can no longer use the Head Look feature.
     
  34. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323

    thank you for bringing this up !! i never had this issue !!
    i guess i will look into this for my project !!
    liking the new update a lot of bugs i have missed !! and cool new features !
     
    Last edited: Jul 21, 2020
    Deckard_89 likes this.
  35. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    698
    Pre
    Pretty sure I have 2.3.1 I last downloaded Emerald on Jan 10, and version 2.3.1 went live a few days earlier, on Jan 6.

    Going from 2.3.1 to 2.4.1, I imagine I will have to redo all my AIs. It won't be difficult. I only have a few active for testing.
     
  36. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    After looking over and over into the code, I see why this is happening.
    LineOfSightDetection uses a raycast from the HeadTransform.position to the direction (one of the targets detected by DetectTarget that was called by UpdateAIDetection ) the direction is the Half of the target or player scale (T.localScale.y/2)

    So the Ai will always aim at the Center of your player, if you change the collider Shape, the Y scale won't change !!
    So the best way to fix this is to get the Collider of the player and create a direction based on that !!
    I end up changing the (T.localScale.y/2) by the collider info
    and i added a Vertical Raycaster that will shoot rays in an angle it's like A Vertical FOV :

    upload_2020-7-22_2-7-14.png

    upload_2020-7-22_2-8-50.png

    And When I move the Object Blocking the Line Of sight even showing a little of the player's feet the Ai will Detect the player.
    upload_2020-7-22_2-11-6.png

    even the other way around :
    upload_2020-7-22_2-12-2.png

    I use this lovely example as a start :https://britishguyinsweden.com/2019/10/27/unity-building-the-foundation-mechanics/

    upload_2020-7-22_2-14-2.png

    this way you can control the number of rays (Angle Steps and the Vertical FoV)





    Edit missed this part :
    here is the code for the collider

    Vector3 T_Size = T.GetComponent<Collider> ().bounds.size;
    Vector3 direction = (new Vector3(T.position.x, T.position.y + T_Size.y/2 , T.position.z)) - EnemyNPCComponent.HeadTransform.position;
     
    Last edited: Jul 22, 2020
    Fibonaccov and Deckard_89 like this.
  37. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    I’ll look into a solution for this. Having an option to use multiple raycasts as Rahd suggested is a good idea.
     
    Deckard_89 and Rahd like this.
  38. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
  39. thaomoua

    thaomoua

    Joined:
    Jun 21, 2015
    Posts:
    4
    Help.

    I just purchased and downloaded 2.4.1. I'm using Unity 2019.4.4f Personal x64.

    I'm trying to create my first AI and the setup is failing. In the release note, v2.4.0 supposedly fixed this issue but I'm still seeing this.

    My prefab is 'skeleton_swordsman' that came with Emerald package.

    Please let me know if you need any more info.

    (update)
    It looks like the Setup Manager isn't working for me (no matter what older unity versions I tried) but I can manually add the Emerald AI System to my prefab and it works.

    ====
    ArgumentException: UnpackPrefabInstance must be called with a Prefab instance.
    UnityEditor.PrefabUtility.UnpackPrefabInstance (UnityEngine.GameObject instanceRoot, UnityEditor.PrefabUnpackMode unpackMode, UnityEditor.InteractionMode action) (at <fd8fd784002f49beab0500d3a24213b9>:0)
    EmeraldAI.Utility.EmeraldAISetupManager.OnGUI () (at Assets/Emerald AI/Scripts/Editor/EmeraldAISetupManager.cs:205)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <fb001e01371b4adca20013e0ac763896>:0)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <fd8fd784002f49beab0500d3a24213b9>:0)
    UnityEditor.HostView.Invoke (System.String methodName) (at <fd8fd784002f49beab0500d3a24213b9>:0)
    UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <fd8fd784002f49beab0500d3a24213b9>:0)
    UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <fd8fd784002f49beab0500d3a24213b9>:0)
    UnityEditor.DockArea.OldOnGUI () (at <fd8fd784002f49beab0500d3a24213b9>:0)
    UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.OpenGate () (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <78b213560771414e9fa6f1b95f5ad8bb>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <819de1aa368e45faa4f78e26c97c62b0>:0)
     
    Last edited: Jul 26, 2020
  40. jangomoose

    jangomoose

    Joined:
    Feb 17, 2016
    Posts:
    38
    Excellent asset, thank you. Any idea why if re-scale an AI it stops it activating ranged attacks?

    Edit, Scrub that, worked it out.
     
    Last edited: Jul 25, 2020
  41. agent_Macgyver

    agent_Macgyver

    Joined:
    Sep 1, 2012
    Posts:
    26
    I think that I am encountering some kind of glitch with companions. Often times, the combat text will show that the companion has received damage, but the health is not decreasing. see the image below. I have three of your skeletons companions attacking the fire mage AI. the skeleton has taken -5 damage, but his health has not changed.

    the only change I have made from your prefabs is the AI layer for all AIs.

    upload_2020-7-26_12-23-20.png

    can you provide any guidance on why this happens? I have noticed when I create a whole new project with only your package, the companions don't receive "-X" health, only the player does. So somehow in my game, the companions are receiving 'Player' damage? I am not sure how this happens.

    While I might be able to rebuild my whole project, I'd like to be sure I don't end up repeating whatever error I made. I tried reseting all the layers and tags to defaults, which seem to be 'respawn' tag and 'water' layer when comparing to a blank new project.
     
    Last edited: Jul 26, 2020
  42. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    I haven’t encountered this so I don’t have an immediate solution. I’ll look into it though and if I can find a solution, I will give you the steps needed to fix it.
     
  43. agent_Macgyver

    agent_Macgyver

    Joined:
    Sep 1, 2012
    Posts:
    26
    Hi BHS, with more testing, I found the issue is the SwitchToRandomTarget script you wrote for me a few months ago. I attached it to all my AI months ago, Only now I have noticed that when the function is called, the AI doesn't deal any damage, it appears as the same "-X" effect that appears when dealing damage to the player.

    I am sorry that I misremembered doing this, my comment of only changing the layers is not correct.

    This must be because the AI has targeted the player first and that not all fields get transferred over to the new random target. So what happens is the AI ends up dealing "player damage" and the combat text makes that appear as "-X". If I don't make those calls, the damage appears as "X" and the companion loses health.

    So I know now that not using this script will fix the damage issue - But I need some kind of function that causes the same effects, otherwise I have the same issue I had months ago - The enemies always run to the player to deal damage before deciding to engage with a companion. that causes the player to get overwhelmed in big battles.

    I have also tried calling " SearchForRandomTarget" directly, but this has the same effect. I have included your Switchtorandomtarget script as a reminder of what you wrote. Could you help me find an alternate way to solve my dilemma?

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using EmeraldAI;

    public class SwitchToRandomTarget : MonoBehaviour
    {
    public float CallDelay = 1;
    EmeraldAISystem EmeraldComponent;
    Coroutine RandomTargetCoroutine;

    void Start ()
    {
    EmeraldComponent = GetComponent<EmeraldAISystem>(); //Get a reference to this AI's Emerald AI Component
    EmeraldComponent.OnStartCombatEvent.AddListener(() => StartGetRandomTarget()); //Create an event that triggers when the AI starts combat
    }

    public void StartGetRandomTarget ()
    {
    if (RandomTargetCoroutine != null){StopCoroutine(RandomTargetCoroutine);} //Stop the courtine if it's already running
    RandomTargetCoroutine = StartCoroutine(GetRandomTarget()); //Start the GetRandomTarget courtine
    }

    IEnumerator GetRandomTarget ()
    {
    yield return new WaitForSeconds(CallDelay); //Delay the call so the first detected object isn't assigned
    if (EmeraldComponent.CurrentTarget != null)
    {
    EmeraldComponent.EmeraldDetectionComponent.SearchForRandomTarget = true; //Enable the SearchForRandomTarget bool which allows the SearchForTarget to look for a random target.
    EmeraldComponent.EmeraldDetectionComponent.SearchForTarget();
    Debug.Log("test");
    }
    }
    }
     
    Last edited: Jul 27, 2020
  44. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,264
    No worries. I’m not sure what version you’re currently using, but within the last few versions, I’ve added a random target option to the Target Pick Type located under the Detections Options. It should give you the same functionality, but apply the correct Target Type enum.
     
  45. agent_Macgyver

    agent_Macgyver

    Joined:
    Sep 1, 2012
    Posts:
    26
    At this time, the random target only works if the AI is set to cautious. Normally, the player is a few paces ahead of the companions when traversing a level, so by the time the random call is made, the player is the only character in the AI's detection range. Using Cautious gives the companions enough time to catch up to the player and fall in the radius before entering combat

    Is there a way to increase the detecction radius as an event? Perhaps when the player is spotted while using cautious, the detection radius can expand by 15%, and then the companions will probably fall into the radius most of the time, allowing them to be targeted by random.
     
    Last edited: Jul 27, 2020
  46. thaomoua

    thaomoua

    Joined:
    Jun 21, 2015
    Posts:
    4
    (my original post is pending approval cause it thinks its a span so I'm posting it again)


    Help.

    I just purchased and downloaded 2.4.1. I'm using Unity 2019.4.4f Personal x64.

    I'm trying to create my first AI and the setup is failing. In the release note, v2.4.0 supposedly fixed this issue but I'm still seeing this.

    ArgumentException : UnpackPrefabInstance must be called with a Prefab instance.


    My prefab is 'skeleton_swordsman' that came with Emerald package.

    Please let me know if you need any more info.

    (update)
    It looks like the Setup Manager isn't working for me (no matter what older unity versions I tried) but I can manually add the Emerald AI System to my prefab and it works.

    (update2)
    If I attach the full error, the forum thinks I spamming so it will not allow me to post it...stupid) let me know if you want the full error
     
  47. GarrettF

    GarrettF

    Joined:
    Jul 4, 2019
    Posts:
    23
    Hi, I've recently started using Emerald AI and have a couple issues. I'm hoping there's something I'm missing or doing wrong and these will be an easy fix.

    First thing, I can't seem to find a way to make the enemy AI automatically detect and start running towards the player no matter what the distance. I have enemies that I spawn into the scene and I want them to attack the player no matter the distance. The distance usually isn't too far but the maximum 100 units range for the detection isn't enough. I have melee enemies and ranged enemies that just sit there until the player gets close enough and it's not that effective.

    Second...this might be a bigger one, but I'm having major performance issues while using enemies with rigidbodies attached. I've narrowed it down to the Emerald AI components. I can have 10 to 20 enemies in the scene at once which have 5-10 rigidbodies attached to them. They are deactivated until activated and destroyed. If I have the enemies with these rigidbodies attached and no emerald AI components then I'm getting around 88 FPS average with the above mentioned 10-20 at once in the scene.

    However, as soon as I add the Emerald AI to these enemies, if I have more than one in the scene i drop to 20-30 FPS and that's just with 2-3 of the exact same enemies in the scene. Emerald AI being the only difference.

    If anyone could shed some light on this issue that would be great. As I'm not sure how to go any further. I could try checking the profiler but I'm not sure if there's a point since its perfectly fine without the Emeral AI components.

    Thank You.
     
  48. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    323
    1- did you set the Ai to Optimize (off-screen )? this will stop the Ai if it's not seen by the camera.



    are the rigid bodies kinematic ?
    is the collision detection discrete?
    if you look into Emerald AI scripts there is not a single line of code that calls rigid body or it's functions. except for EnableRagdoll DisableRagdoll and InitializeAIDeathCoroutine.
    I use rigid bodies for better collision detection on mobile, i have tested 10 Ai on moto x 2013 it runs about 45-34 fps .
    not using the rigid bodies gains about 6 fps maybe 10.
    maybe your physics settings?
    would love to see the profiler results.
     
  49. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,145
    @BHS is the code update included in 2.4.1? TIA
     
  50. CraigHubbard

    CraigHubbard

    Joined:
    Jan 20, 2019
    Posts:
    3
    Hello, I just got the Opsive integration by @magique implemented but wasn't able to get an enemy to detect my player with either detection option, so it occurred to me the one suspicious difference between my player and the Emerald player is that mine has a capsule collider as a child while the Emerald player has one on the parent object. So I added a capsule to the parent of my player and suddenly it worked. Is there a hard requirement that you can't have the collider nested?
     
unityunity