Search Unity

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

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

  1. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,762
    My apologies, I misunderstood.

    If your player uses a Character Controller to move, which in the case of the included Emerald AI player it does, then the AI treats the player as a rigidbody movable object.

    One way around this is to put a Nav Mesh Obstacle on your player. This will allow your AI to avoid the player instead of pushing it away. However, using this method sometimes allows the player to push the AI, which doesn't happen often.
     
  2. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    @BHS:
    I have some problems with a NPC using RFPS. It's a flying object. First of all it's attacking the player very rarely even with booth attack speeds set to 0. It sticks in the combat idle animation. Second when I change the Agent Base Offset to something more the .5 it's not attacking at all anymore. With my animals as NPCs everything works as expected, except
    the LineOfSight which is not working at all for all NPCs.
    Any suggestions?

    Unity 2018.1.9f1 Windows 10 64bit
     
    martire and AlexandreDelan like this.
  3. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Thanks for the suggestion. The official advice from BHS was to try adding a nav mesh obstacle, however, if that doesn't work out, I will try adjusting the mass of the player and agents, and see how well Unity physics handles the issue.
     
  4. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    @BHS

    I am very happy using Emerald AI in my Projects. I am using ranged Attacks with KryptosFX and everything is working fine, the "Heat Seeking" abilitiy is also great. I am using the "Effect on Collision" along with ranged attacks and would love to see a similar checkbox for the collision effect to update its position with a moving player, so the player cannot walk away from a triggered collision effect. Can u add this into the next/future update?
     
  5. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    212
    can i integrate this with unity's top down survival shooter project ?
     
  6. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    236
    Any word about adding support for Opsive Third Person Controller?
     
  7. Revelation_Jeff

    Revelation_Jeff

    Joined:
    Jul 17, 2012
    Posts:
    141
    Hi @BHS When are you expecting to release your Update including Root motion support for animation? Thanks!
     
    AlienMe likes this.
  8. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    @BHS, if you run the 3rd person demo in Emerald AI, and you kill the companion, then the dead companion remains follow you around, floating in the air.

    I know, not supposed to kill the companion, but I didn't read the text after the 'Press 1 to spawn....", and the guy kept following me around.... :D
     
    Revelation_Jeff likes this.
  9. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    Hi @BHS

    I tried to use your script on my Emerald AI Agents, but I cant get it to work properly. While the overall function works as expected, the Agent's animation does not reset and he will remain in the dead animation state, but following the Player and also attacking as it should. How to fix plz?
     
    Last edited: Aug 31, 2018
  10. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,269
    I get the same thing. It will only reset if you leave the detection radius.
     
    Weblox likes this.
  11. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,762
    Yes, this sounds like a good feature.


    I haven't tested it, but it should be possible by modifying the player damage and AI damage to reference the Emerald AI and Unity's player.


    I have tried a couple of times to contact the developer of Opsive TPC and they haven't responded. The last time I did receive a reply, they said to wait for version 2.0. I can try again as I have had a lot of requests to make an integration tutorial for it.


    I don't have an ETA, but it's currently being worked on.


    I wasn't aware of that. :) I will get it fixed with the next update.


    This is because of the Emerald AI Animator Controller needs a connection to the Idle (Combat) state.

    Create a connection from the Dead state to the Idle (Combat) state. For the Conditions, have Idle (Combat) and set it to true.

    I'll get this fixed with the next update, but this should allow AI to properly go back to the needed state after respawning.

    AnimatorControllerFix.png
     
    Weblox likes this.
  12. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @BHS ,

    TPC2 and UCC due out imminently from Opsive. They're on the last release candidate. So probably best you only tackle this on release of the new versions which are v different under the hood...

    I was wondering if you could work on an integration with CAT Studios wonderful GameCreator ?
     
  13. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    236
    @BHS
    What about TPC version 1.3? I'm not planning to upgrade to version for sometime.
     
  14. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    @BHS - Awesome! Great to hear. :D

    Thank you so much for this quick and easy fix. It's working great - now I can finish my Demo Level. One thing I found that the Respawn Script does not trigger the onStart.Event after resetting the Emerald Agent. In my case I have Effects on the Agent that I enable in the OnStart.Event and disable in the OnDead.Event. These will not be reenabled. To fix this I have added the OnReset.Event to the RespawnAI.cs , so one can reenable all logic that might exist in the OnStart.Event. :confused:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Events;
    5.  
    6.  
    7. namespace EmeraldAIExample
    8. {
    9.     public class RespawnAI : MonoBehaviour
    10.     {
    11.  
    12.         public UnityEngine.Events.UnityEvent onReset;    // <---ADDED THIS LINE FOR RESET EVENT
    13.  
    14.  
    15.         //The seconds needed before respawning
    16.         public int RespawnSeconds = 300;
    17.  
    18.         //The reference to the Emerald AI system
    19.         Emerald_AI EmeraldAIReference;
    20.  
    21.         //The respawn timer that will track the seconds passed
    22.         float RespawnTimer;
    23.  
    24.         void Start()
    25.         {
    26.             //Get the reference to the Emerald AI system
    27.             EmeraldAIReference = GetComponent<Emerald_AI>();
    28.         }
    29.  
    30.         void Update()
    31.         {
    32.             //Increase the RespawnTimer, but only when the AI has been killed
    33.             if (EmeraldAIReference.CurrentHealth <= 0)
    34.             {
    35.                 RespawnTimer += Time.deltaTime;
    36.  
    37.                 if (RespawnTimer >= RespawnSeconds)
    38.                 {
    39.                     //Reset the AI and set the timer back to 0 to be used again, if needed.
    40.                     EmeraldAIReference.ResetAI();
    41.                     RespawnTimer = 0;
    42.                     onReset.Invoke();      //ADDED THIS LINE FOR RESET EVENT!
    43.  
    44.                 }
    45.             }
    46.         }
    47.     }
    48. }
    49.  
     
    Last edited: Sep 1, 2018
    SickaGames1 likes this.
  15. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    Hi so I'm having a weird issue with the Emerald AI window in the inspector, for some reason its stretched. No mater how big I make the window I still have to scroll to see all the info and buttons. Im using unity version 2018.2.6f1 but it was doing it on the previous version to. It's only the Emerald AI window, is this a unity issue?
     
  16. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    Stop NPC. So I'm using pixel crushers dialogue system and I can't get the Emerald AI to stop moving when I interact with it. I have my own script that calls some methods on the ai when the conversation is started, but I cant get the results I want. I wanted the ai to have waypoints but couldn't get it to stop at all that way, so I went with dynamic but my first attempt by switching from dynamic to stationary left him spinning in a circle in place. So I tried the pause() method which says its good for dialogue however that does nothing. I then tried to just disable the ai component, however that leave the ai in a non stop movement in the direction he was heading.

    I am calling pause() from my own script, and its getting called but is this not the right way to go about this. I just want the ai to start/stop during my dialogue.
     
    Last edited: Sep 5, 2018
  17. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I made an AI but he seems to be running backwards, and facing away from me, anyone know how to fix ?
     
  18. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    Make a Game Object as parent for your model. Then copy the animator from the model to the Parent and delete from model. Now you can rotate the Model child's Y - transform 180° to face in the direction of the parent GO objects blue arrow. Then run the Emerald Setup Manager on the Parent GO and you should be good. This is also mentioned in the Docs if I remember it right.
     
    radiantboy likes this.
  19. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Does anyone know why when you copy and paste the emerald AI script to another character he doesnt animate anymore?

    EDIT: got it, if you turn on debug mode and assign the right AI Animator it works.
     
  20. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I have 3 cool ai working, but theyre running through each other, whats the best way to avoid this? I added nav mesh obstacles but then they all go crazy sprinting 10x the speed back and forth weirdly.

    edit: managed to get the nav mesh obstacles to work but now as the guys run at me i "bounce" off their nav mesh obstacle and end up standing on their head!..
     
    Last edited: Sep 5, 2018
  21. aflmnv

    aflmnv

    Joined:
    Jul 5, 2018
    Posts:
    1
    Hi, how take damage animation on run from shooting. Its not plaing. In idle - damage play, from run - dont play. How can i do damage animation from evry bullet to enemy?
     
  22. RonnyDance

    RonnyDance

    Joined:
    Aug 17, 2015
    Posts:
    557
    Yeah lot of Games have this feature. Where you see a NPC walking to another npc and starts talking etc. So wayspoints should have an option like stay there for XX-XX Seconds and play this random animations from a animtion list. This will bring life to your project and AI.

    Yep would be really cool. Like a priest casting a Heal Aura as idle animation + effect.

    Would be great if you could this make more easy like changing the creature name or title in the inspector. Because right now the font and the position does not really fit for me and I didn't found the Canvas. Gonna look closer to it this weekend.


    Really love what you have planned. I just hope that the update takes too long because you want to create one big "master" update ;)

    Btw. how is the UNET support going? Saw that you told one guy in the forums that it will included in one further update. Now that uMMORPG is on sale I would love to use your AI in Multiplayer games.

    Keep up the good work.
    Ronny
     
    Last edited: Sep 6, 2018
    SickaGames1 likes this.
  23. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,269
    I am hoping that we are able to make Boss fights and NPCs to have a little more of a complex fighting style by adding in more combat mechanics (do this series of moves at 60% ect..). Also do you know how to let partial damage happen when an Emerald AI agent attack an Invector TPC when blocking. The TPC could have no shield and block with its hands currently letting 0 damage through. Maybe you could write if there is a shield then take no damage otherwise let it through.
     
    Last edited: Sep 6, 2018
  24. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Anyone been able to intergrate this to combat framework?
     
  25. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Has anyone noticed performance issues with Emerald? My game goes from 50fps to 15fps just by turning on 3 AIs, is there anyway to further optimise this? Im finding physx.postIslandGen() is using a lot of CPU (40%).. I have them set up to disable when offscreen and immediately the fps goes back up and theres no calls to postIslandGen. One weird thing is if they run from some areas to another it speeds up A LOT and the calls to postIslandGen go down drastically, even though they seem to have just moved from one cube to another, any ideas?
     
  26. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    I hope someone can help. I've just purchased this asset and am trying to do the following.
    I have a character that is wandering around.
    I want to create a script to add to this character that has a countdown timer/value.
    When this value gets below 50 (for example) I want to set the destination to a specific location and set the wander type to destination.

    Below is my code but I get the error on the SetDestination because it can't convert a Vector3 to a Transform.

    I also tried this with an object and sent the transform that way but it doesn't do anything.

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

    public class wildlifeBehaviour : MonoBehaviour {

    // Reference to AI Controller
    private Emerald_AI ai;

    //GameObject.GetComponent<Emerald_AI>().SetDestination();

    // Use this for initialization
    void Start () {
    ai = GetComponent<Emerald_AI>();
    SetDestination();
    }

    // Update is called once per frame
    void Update () {

    }

    void SetDestination()
    {

    ai.SetDestination(new Vector3(70.55f, 139.34f, -79.5f));

    }

    }

    EDIT: I changed it to look at a GameObject.transform instead or a Vector3 as that just doesn't work. I ran it again and it worked, ONCE. I ran it a second time and the destination widget appeared in the scene window but the character walked off in a different direction as though they were still wandering. Once they stopped they were stuck and didn't move again.
    Is there away to change the wander type back to wandering?
     
    Last edited: Sep 7, 2018
  27. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    When I try to play an Emote Animation I'm getting the following error.

    UnassignedReferenceException: The variable overrideController of Emerald_AI has not been assigned.
    You probably need to assign the overrideController variable of the Emerald_AI script in the inspector.
    UnityEngine.AnimatorOverrideController.set_Item (System.String name, UnityEngine.AnimationClip value) (at C:/buildslave/unity/build/Runtime/Animation/ScriptBindings/AnimatorOverrideController.bindings.cs:53)
    Emerald_AI.PlayEmoteAnimation (Int32 EmoteAnimationID) (at Assets/Emerald AI 2.0/Scripts/System/Emerald_AI.cs:3000)
    UnityEngine.Events.InvokableCall`1[System.Int32].Invoke (Int32 args0) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:207)
    UnityEngine.Events.CachedInvokableCall`1[System.Int32].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:345)
    UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:70)
    Emerald_AI.Update () (at Assets/Emerald AI 2.0/Scripts/System/Emerald_AI.cs:1334)
     
  28. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @BHS ,

    In broad terms, what's the development Roadmap for Emerald AI from here? What are the priorities in terms of Integrations?
     
    Last edited: Sep 8, 2018
  29. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    How do you attach that script? It doesnt let me just create a new script and drag it onto the agent like a component
     
  30. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Use the setup wizard. Look at the docs, theres step by step.
     
  31. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    AnimationEvent Hit has no receiver ?
     
  32. C_p_H

    C_p_H

    Joined:
    Nov 24, 2014
    Posts:
    153
    @BHS
    Just out of curiosity, why not utilize Raycast Hit points rather than standard NavMesh?
     
  33. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,762
    Sure, I can reach out to the developers to see if I can make an integration tutorial for it.


    I'll try to contact the developers to see if I can get a copy of the 1.3 version so I can make an integration tutorial.


    You're welcome. Thanks for the updated script. I totally forgot about the events. :)


    Hey there,

    If you are talking about the Setup Manager being docked on the Unity Inspector, it's because it's designed to be used as a Window. I wasn't aware it did that when having it docked. I will note this to be fixed with the next version.

    I actually just recently encounerted this when working on better support for Quest Machine. Using Pause() should be working, but the AI may continue playing its walking animation. Try adding AnimationIdle(); in the Pause() function in the Emerald_AI script. I also realized that having the turn animations set to loop can cause the AI to spin so try setting your AI's turn animations to not loop. This is how I got the AI stopping and resuming correctly.


    AI can avoid each other by setting the quality of an AI's Avoidance Quality. The higher the quality, the more they will avoid each other. The next version will have AI avoid each other better using raycasts. Also, using NavMesh Obstacles on NavMesh Agents is something Unity said may cause undesirable affects.


    You would need to use the projectile attack type instead of the melee type.


    I will be redoing the AI's UI so they all use the Canvas system. I used Text Mesh because there was a bug previously with the Canvas system that would cause huge spikes of lag when enabling or disabling it. This has been fixed now so I can implement a better method.

    I haven't had the time to look too much into UNET support as I'm working on updating two of my main systems. I do know it's currently possible with a few modifications though.


    Boss fights will be more doable when the ability system is implemented. It will allow users to customize attacks and projectiles an AI can use with options to choose odds for each one.


    This is most likely happening because your AI's Detection Radius is too high. I found that a good balance is between 25 to 40. With these settings, I can have ~40 AI in a relatively dense scene with good performance.


    When calling the SetDestination() function, your AI's Wander Type is set to Destination. After the AI has reached its destination, it stays put because it has reached its destination. If you would like your AI to continue wandering once it arrives at its destination, you would need to watch its AIReachedDestination variable. This variable is set to true after an AI has reached its destination. Once it has, you can call ai.WanderTypeRef = WanderType.Dynamic; (so it can wander again) and update its starting position to StartingDestination = ai.transform.position; so it can wander again around its new destination.


    How did you create an AI? This usually happens when you drag the Emerald_AI script directly on an object. Use the Setup Manager and assign your AI's animations. A tutorial on this can be found here covering the animation portion: https://docs.google.com/document/d/...2njM7Jx9pYlqgbtM8/edit#heading=h.q018oimvd8i0


    The next version of Emerald AI will get herd/group, breeding, and Root Motion support. As far as integrations go, Emerald AI has its integrations covered with Integration Tutorials. I plan on covering Opsive TPC soon. UniStorm will have integration within the next version of two that will add schedules based on UniStorm's time.


    This is unrelated to Emerald AI. It sounds like your animation has an event on it. For more information on Animation Events, see Unity's documentation here: https://docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html


    I have plans to look into additional options for other options than just Unity's NavMesh. Unity's NavMesh has worked great so far, other than the lack of proper support with procedurally generated levels.
     
    radiantboy, C_p_H and Weblox like this.
  34. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    thank you very much, Im happy you are replying and developing. I know all the ICE AI guys are freaking out now because he left us in the cold. I actually love this package, but I would like if you can fix it so that enemies can't hurt you even when they are not on the same Y coord, ie they can hurt you if you're above them, quite a large bug I'd say. Great work though!
     
  35. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    Thank you for your replies, both helped apart from the comment "update its starting position to StartingDestination = ai.transform.position. I can't find any mention of "StartingDestination" in any of the docs, I assume it is a position that is the center of the AI's wander radius, but i can't confirm this or set it. Can you elaborate?
    As a work around I've put the AI's inside an empty and set that as the destination when they reutrn "home".
     
  36. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    Also, how do you turn on DEBUG mode as I have an issue where I set the AI destination via a script and the AI starts heading towards it and then seems to decide to move off in a different direction to a random spot which is NOT the destination (as the gizmo for the destination doesn't change in the scene view during this process) and when it reaches this random spot it triggers the "Reached Destination Event".

    I have attached a screen shot of an example, the yellow cube was set as the destination and the AI (a cow) started walking towards it, but suddenly changed direction and ended up where it is in the image and triggered the Reached Destination Event. The stopping distance is set to 1.75. When the AI does this (and it isn't everytime, then the distance it stops varies a lot).
     

    Attached Files:

  37. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Someone do an intergration with third person cover shooter
     
    Munken likes this.
  38. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,630
    If anyone is interested, here are some interesting articles I found while researching raycast-based navigation.

    https://andrewfray.wordpress.com/2013/03/26/context-behaviours-know-how-to-share/

    http://www.gameaipro.com/GameAIPro2...havior-Driven_Steering_at_the_Macro_Scale.pdf
     
    C_p_H likes this.
  39. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,269
    How is the next update coming along for Emerald?
     
  40. nellecter

    nellecter

    Joined:
    Feb 9, 2017
    Posts:
    4
    Hi, i recently bought Emerald AI for an UFPS based project.
    I followed your integration tutorial and for the first time for me it works on my very first attempt!! (thanks).
    Now..Lets talk about my questions :

    1) how can i implement grenade or any other damage caused by explosion?:
    Until now the Ai receive damage when i shoot it and when i attack with melee weapons..

    2) Is it normal that the enemy can attack the player even if is on a different height..i mean the enemy are on the base floor and i was on the floor on top of.. and they was able to hit me.

    3) is there any chance to let the internal UFPS damage arrow that show the direction where you got hit from works?

    I really hope you can help me...
    Thanks in advance
     
  41. hoodoo

    hoodoo

    Joined:
    Oct 19, 2012
    Posts:
    154
    Hi @BHS and hello fellow developers. I purchased Emerald AI in the current sale and looking forward to using it!

    I was previously using plygame and also ICE. If anyone has suggestions about the best tutorials to get started, it would be much appreciated. I'd like to also dig into the extensibility through the API/Events. Has anyone hooked in Node Canvas to do specialized behaviour?
     
  42. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    98
    I use UFPS with Emerald AI. I use zombies as enemies in my game. Is it possible to do localized damage in Emerald AI enemies? I mean, if I hit the enemy leg the damage is multiplied per 1.2x. If I hit the head the damage is multiplied per 5. Is it possible to do something like that with Emerald AI?
     
  43. DeanMarquette

    DeanMarquette

    Joined:
    Feb 10, 2015
    Posts:
    165
    How can I change the rotation of the projectile? When ever the bullet comes out it is alway on its side with the particles. No matter how much I change the rotation it always comes out on its side.

    Also none of the animations that come with it are for humanoid characters, why? This would probably solve half the problems on this page.
     
    Last edited: Sep 12, 2018
  44. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    How do you determin who is attacking an AI? For example is the attacker another AI or the Player? As I don't want the Player to earn experience if one AI kills another.
     
  45. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,269
    You have to s
    That is what factions are for. If an AI is set to be friendly or neutral to that faction, then they won't attack each other.
     
  46. SickaGames1

    SickaGames1

    Joined:
    Jan 15, 2018
    Posts:
    1,269
    I think it would be an awesome idea to have a Horse Animator Pro mount, once dismounted act like an AI companion fighting along side my character and then stop fighting once mounted again. ie. riding a dragon and then have it fight!
     
    BHS likes this.
  47. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    Hi, sorry I wasn't to specific before about the window issue. It's not the setup window its the Emerald_AI window on the AI Object., If you take a look at the picture you will see that I can stretch the window open and no matter what it never shows fully, I always have to drag the slider at the bottom to the left to update the numbers etc. I have a 27 inch monitor and even if I stretch that window all the way it still doesn't show the whole Emerald_AI window, pretty much how you see it now is how it stays,

    upload_2018-9-16_18-50-35.png
     
  48. Darrkbeast

    Darrkbeast

    Joined:
    Mar 26, 2013
    Posts:
    125
    Enemy and Companion set up issues. Not sure if its related to using Invector's controller but I can't for the life of me get either the enemy or companion ai to work right. For the enemy sometimes he will attack, while others he just follows me around. I've tried the settings, and sometimes it will work while others not so I have no clue why.

    For the companion I can only get him to follow me for a few meters and then he will stop and just walk at a wall in place.

    I have backed navmesh, followed the set up from the demos, tags and layers set up too. Not sure if maybe something changed in relation to Invector.

    (Update)

    So I took the prefab skeleton, added it into my scene and copied the same thing I had for my enemy and the skeleton worked better. Not sure why my enemy just kind of goes crazy. Adjusting some layers helped a bit but mine still acts like it cant find the play unless Im standing a certain way.
     
    Last edited: Sep 17, 2018
  49. DanBanner

    DanBanner

    Joined:
    Dec 11, 2015
    Posts:
    29
    You misunderstand. I want AI to attack each other. For example I have a Wolf AI that I want to attack a Cow AI and kill it. I also want the player to be able to attack the Cow and earn experience, I use the On Death event to add experience to the player.
    The problem is that when the Wolf kills the Cow, the On Death event triggers and the Player earns experience which shouldn't happen.
    Any ideas?
     
  50. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I looked a this and I see that the OnDeath doesn't pass any parameters so there is no way to directly tell who killed the cow in your example. However, it's possible to make that determination with a little extra work. Here is a script that I wrote that you can attach to an Emerald_AI agent for determining if a player attacked the cow.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AIEvents : MonoBehaviour
    6. {
    7.     private Emerald_AI _emeraldAI;
    8.     private bool playerAttackedMe = false;
    9.  
    10.     private void Awake()
    11.     {
    12.         _emeraldAI = GetComponent<Emerald_AI>();
    13.     } // Awake();
    14.  
    15.     public void OnDeath()
    16.     {
    17.         if (playerAttackedMe)
    18.         {
    19.             // TODO: Award experience points here
    20.             Debug.Log("OnDeath()");
    21.         }
    22.         playerAttackedMe = false;  // reset in case this object is re-used in an object pool
    23.     } // OnDeath()
    24.  
    25.     public void OnDamaged()
    26.     {
    27.         if (_emeraldAI.DamageInitiator == Emerald_AI.TargetType.Player)
    28.             playerAttackedMe = true;
    29.     } // OnDamaged()
    30. } // class AIEvents()
    31.  
    This requires some additional code added in the Emerald_AI class as well as follows:

    First at the top of he script

    Code (CSharp):
    1.     public TargetType DamageInitiator { get { return damageInitiator; } }
    2.     private TargetType damageInitiator;
    3.  
    Then in Damage function:

    Code (CSharp):
    1.     public void Damage (int DamageAmount, TargetType TypeOfTarget){
    2.  
    3.         damageInitiator = TypeOfTarget;
    4.  
    5.  
    Once you attach this script to your AI, you'll have to add references to the Death and Damage events.

    [EDIT]
    You could make this smarter by adding a damage queue to Emerald_AI and you could push a struct onto the Queue that contains the amount of damage and the target of the attack. In the OnDamaged function you could then just check the target type by popping from the queue. You could also compare the amount of damage caused by the player to the AI's max health to see if the Player was the primary person responsible for the AI's death. That would help in the event that the player and a wolf were attacking the cow and the player would then only get experience if it did the majority of damage.
     
    Last edited: Sep 17, 2018
    BHS and Weblox like this.