Search Unity

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

AI Behaviors Made Easy! (Walker Boys)

Discussion in 'Assets and Asset Store' started by profcwalker, Apr 22, 2012.

  1. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hey all, sorry for the silence. Can someone send me a bug report using the "AI Behavior > Contact Us or Report a Bug" menu item with steps to reproduce the problem area. I've been working on a client project in Unity 4.6 and am not experiencing any issues with it not working.

    edit: Please also let me know if you're editing in the Project view or the Scene view. This would be a very important detail.

    Thanks a bunch,
    Nathan
     
    Last edited: Dec 18, 2014
  2. VENOMOUS09

    VENOMOUS09

    Joined:
    Dec 27, 2014
    Posts:
    37
    how do i get this to work with UFPS ? is there a C# code i have to place some where to get the ai to be able to hit and take damage from UFPS
     
  3. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    vp_DamageHandler is your script reference you want to damage
    Source is the transform root who deal damage

    vp_DamageHandler.Damage(new vp_DamageInfo(damage, Source));
     
  4. VENOMOUS09

    VENOMOUS09

    Joined:
    Dec 27, 2014
    Posts:
    37
    thanks every one i got it now
     
  5. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Does this support Aron Granberg's A* system out of the box? I mainly need a great FSM, but I'd rather not rejigger an already great pathfinding system. :)
     
  6. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Unless anything has recently changed with his pathfinding system we have a menu option to enable using it. Just make sure you add his plugin into your project first, and then use our menu options or you will get errors.
     
  7. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Perfect, thank you! :)
     
  8. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I bought and installed the package, it looks great so far but I hope you don't mind two quick questions:

    1) I'm getting two errors from GoToRandomStateTrigger, both from line 12: AIBehavior.ExcludeFromSubTriggersList is not an attribute class, and type or namespace name ExcludeFromSubTriggersListAttribute could not be found. Tried deleting the entire folder and re-downloading re-installing, but the error persists. Temporarily getting around it by commenting out [ExcludeFromSubTriggersList] on line 12.

    2) A lot of my current, cobbled-together AI logic is based on constantly consulting a schedule and utility stats to determine the desired behavior: if any one utility stat (hunger, thirst, hygiene) is in the red, the character should find the appropriate item and activate it to reduce said stat, if all utility stats are below some arbitrary value, they should check their schedule to see what task they should be pursuing. I'm wondering how you would recommend organizing this with AI Behaviors?
     
    Last edited: Jan 7, 2015
  9. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    I bought this asset a while ago and have been playing with it recently. I was hoping to get some help with a trigger script. Since I'm not a programmer (obviously since I'm using this asset), could Nathan or someone else knowledgeable help me out?

    I want a Key NOT Being Pressed trigger. I already modified one trigger script to see if a key is currently pressed (as opposed to down/up), which seems to work ok, but I can't for the life of me get the key NOT being pressed to work.

    This tells me the left hand side of an assignment must be a variable, property, or indexer, and I'm sure that means something but.... Any ideas of what I can do?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7.  
    8.  
    9. namespace AIBehavior
    10. {
    11.     public class KeyNOTBeingPressedTrigger : BaseTrigger
    12.     {
    13.         public KeyCode keycode = KeyCode.C;
    14.    
    15.    
    16.         protected override void Init()
    17.         {
    18.         }
    19.    
    20.    
    21.         protected override bool Evaluate(AIBehaviors fsm)
    22.         {
    23.             if (Input.GetKey(KeyCode.C) = false)
    24.             {
    25.                 return true;
    26.             }
    27.         }
    28.     }
    29. }
     
    Last edited: Jan 9, 2015
  10. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    if(Input.GetKey(keycode) == false) or if(!Input.GetKey(keycode))

    but thats going to return true and change your state as long as you do not touch your keyboard
     
  11. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Thank you for the reply, Damien, but I'm still getting errors within the context of the code. It tells me:

    When I use the following script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7.  
    8.  
    9. namespace AIBehavior
    10. {
    11.     public class KeyNOTBeingPressedTrigger : BaseTrigger
    12.     {
    13.         public KeyCode keycode = KeyCode.C;
    14.      
    15.      
    16.         protected override void Init()
    17.         {
    18.  
    19.         }
    20.      
    21.      
    22.         protected override bool Evaluate(AIBehaviors fsm)
    23.         {
    24.             if (Input.GetKey(keycode) == false)
    25.                 {
    26.                     return true;
    27.                 }
    28.         }
    29.     }
    30. }

    So I'm assuming for some reason AI Behaviors doesn't like that logic? Not sure what to do. I just need the trigger to register "true" when the key is not being pressed.
     
  12. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    1. if (Input.GetKey(keycode) == false)
    2. {
    3. return true;
    4. }
    5. else
    6. {
    7. return false;
    8. }
     
  13. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Wow I'm an idiot. It turns out all I had to do was add the ! to line 24 of the original KeyDownTrigger script, and instead of saying GetKeyDown, it switched it to GetKey. Like this:

    Code (CSharp):
    1.             return !Input.GetKey(keycode);
    For some reason I thought I needed an if/then statement there, but I guess not.

    Thanks again for the replies, Damien.
     
  14. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm probably being silly, but I am having an incredibly difficult time getting this to work. Am I correct that the workflow to get this working with aron granberg's A* system and a mecanim-rigged NPC is to import the package, fix the errors it comes with, select the AI Behavior > Other > Astar Pathfinding Project option from the top menu, then select an NPC, and with that NPC selected, hit AI Behavior > Mecanim Setup from the top menu? I've tried this numerous times, but it always results in extremely glitchy performance.
     
  15. PabloXl5

    PabloXl5

    Joined:
    Feb 16, 2012
    Posts:
    4
    I'm using this AI Behaviors in a game I'm working to run on the Wii U. Will it work with Unity for Wii U or do I need to look into other AI solutions to continue on? I really love the package so I'm hoping for the best!
     
  16. PabloXl5

    PabloXl5

    Joined:
    Feb 16, 2012
    Posts:
    4
    Yeah, if I don't get an answer then I guess I won't get one but I thought I'd post about it here anyways. Right now it doesn't seem compatible since I get a wealth of errors. I thought there might be some solutions and I've looked around the web but couldn't find anything. I'm already looking into other avenues for the AI. If they answer, great! At least I'll know but I can't wait around for weeks or months to hear back.
     
  17. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Likewise, I get a bunch of errors from this, and while they were kind enough to email me back once, I haven't heard anything in over a week- I'm calling this $90 down the drain and moving on to different solutions.
     
  18. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    The ability to duplicate a state, along with all of that state's triggers, would be very helpful.
     
  19. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    maybe you should explain what playmaker action you need? have you ever tried to setup an AI agent? it does not require much interaction from other assets
     
  20. Kitt12

    Kitt12

    Joined:
    Dec 28, 2014
    Posts:
    1
    hello ,

    i had bought this Asset , this asset very very amazing plugin AI . Really simple to making AI player , I love it.

    But I want ask something, how to making popup text GUI after Flee ? like a navigation NPC talking after flee on the position idle
    please give me idea or tutorial for it .

    thanks
     
  21. Enki

    Enki

    Joined:
    Jun 2, 2013
    Posts:
    20
    The amount of negativity here is really disparaging. This asset is old; one of the oldest here even. However! Yes it works well with 4.6 and I see nothing offhand that will break with 5. FSM is but one of the manners to handle your AI needs, and will not be suitable for every environment. If you find it's the proper answer for you though, I'd say this is one of the better done implementations with or without any further future updating.
    So please, just stop with all this 'They made their money and it's now abandoned' and the 'I demand Playmaker support'.
     
  22. Enki

    Enki

    Joined:
    Jun 2, 2013
    Posts:
    20
    You cannot program and therefore you expect others to do so for you? I call BS on that. And 'they' are supposed to do what exactly? Add support for other products that were written much later, just because you decided to buy it? Good luck with that.
     
  23. Enki

    Enki

    Joined:
    Jun 2, 2013
    Posts:
    20
    Funny, only a few hundred of those were sold in 79; you must have been one of the original owners then. The first code I wrote would have been punch cards. A few years later my rich friend bought a TRS-80 and let me play. I find it odd any coder would say they can't do a fairly simple function in ANY language, previously used or not.
     
    andreadoria likes this.
  24. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    you didnt explained once: What playmaker action do you need to do with this AI behavior? i really feel that playmaker do not fit for this you need to change a Behavior? special action and trigger can be extended with much better result than a "playmaker hack"
     
  25. AlteredPlanets

    AlteredPlanets

    Joined:
    Aug 12, 2013
    Posts:
    455
    is there off nav mesh support?
     
  26. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Has anyone had luck making the NoPlayerInSight trigger use a delay? It's really annoying to have the AI walking toward you in a "Chase" (seek) state and then instantly change states when the player leaves its sight.

    I tried using a Timer trigger, but that only works from the time the state starts, not from the moment the player leaves sight.

    The only other solution I have found is to transition on NoPlayerInSight to another Seek state that has the timer on it, and go back to the "Chase" state if LineOfSight is restored, but it kinda sucks to have to build an extra state just for that.

    Any suggestions?
     
  27. GetLitGames

    GetLitGames

    Joined:
    Sep 24, 2014
    Posts:
    11
    In reply to the "why can't they spend a few minutes a week here" maybe because an old forum thread on the unity forums isn't where they do support.

    They posted a reply here and it said:
    Can someone send me a bug report using the "AI Behavior > Contact Us or Report a Bug" menu item with steps to reproduce the problem area. I've been working on a client project in Unity 4.6 and am not experiencing any issues with it not working.

    They are referring to the menu inside Unity labelled AI Behavior, and the submenu labelled "Contact Us or Report a Bug" they want you to use that not post here.
     
  28. WaqarKhan703

    WaqarKhan703

    Joined:
    Sep 9, 2013
    Posts:
    7
    Hi Guys ,

    I seek some help with AIbehaviors. I want to access the patrol state of the enemy. What I'm trying to do is after instantiating an enemy I want it's waypoint group to be initialized from code/dynamically. I've tried for a clue in documentation but wasn't able to find the solution. Please help me . Thanks In Advance

    Regards
     
  29. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Everyone,

    I'll try and get to some of the posts in here.

    First is that, as someone else mentioned the best way to contact us is probably not through this forum. The best way to contact me is via email at nathanwarden@icloud.com

    I've had this question asked a few times now, so I will now include the following code in the ExampleScripts folder. In the meantime, here's the code:

    Code (csharp):
    1. using UnityEngine;
    2. using AIBehavior;
    3.  
    4. public class SetPatrolPoints : MonoBehaviour
    5. {
    6.    public Transform patrolPoints;
    7.  
    8.  
    9.    void Awake ()
    10.    {
    11.      AIBehaviors ai = GetComponent<AIBehaviors>();
    12.      PatrolState state = ai.GetState<PatrolState>();  
    13.  
    14.      state.SetPatrolPoints(patrolPoints);
    15.    }
    16. }
    Someone above mentioned that the NoPlayerInSight trigger stops a chase and should include a time, I agree and will look into adding it into the next update which will be coming soon.

    If I missed an important question, bug or otherwise, please email me at the address above :)

    Thanks,
    Nathan
     
  30. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    I wanted to include this as a separate post because I know some people are curious about whether AI Behavior will be compatible with Unity 5.

    The answer as of about an hour ago is yes! It will be available probably in the next few days with the next update I put on the Asset Store. Only 10 lines of code needed to be changed. 4 were critical due to using AddComponent with strings. 6 were from using audio.[whatever] and needed to be changed by caching a variable using GetComponent<AudioSource>() first.

    Since I'd like to keep AI Behavior as a single 4.x upload (but just for now) there will be some slight graphical issues due to shaders changing. For instance, in the mecanim example scene the AI character will come in pink, simply change the shader to the new "Standard" shader and it will look correct again.

    I already have a Unity 5 branch in my repository and I plan to use the new multi-package system for the Asset Store soon, but just not at the moment.

    Thanks,
    Nathan
     
  31. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Hey Nathan, since you're here - is there a possibility of adding some type of offset to the "within distance" trigger? Presently, it always spawns the red detection sphere at the AI's base. I want to give my AI a better sense of direction, whether something is to their left, right, rear, front, etc. The easiest way i could figure to do that would be to expose some position offsets for the sphere that's generated with the trigger.

    Or maybe exposing shape options? Cone vs Sphere?

    Another possibility could maybe be the option to add another class of LineOfSight triggers, so there could be cones that face as many directions as needed, instead of just the main LoS trigger that serves as the eyes.

    I basically just want to be able to add specific reactions to the AI based on positioning of the player vs AI.
     
  32. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    I agree, that sounds like a great idea for a trigger! I'll add that to my todo list. :)
     
  33. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Fantastic! Thanks!
     
  34. AlteredPlanets

    AlteredPlanets

    Joined:
    Aug 12, 2013
    Posts:
    455
    good to see the dev still working on this
     
  35. eliteslayer

    eliteslayer

    Joined:
    May 12, 2013
    Posts:
    64
    Hi,
    Ive had this kit for a while and it looks fantastic, but my problem is i cant get my own character models to work and have the AI shoot from a weapon, further more ive tried to add knifing for when player is up close, and grenade and flash bang throwing for when the player is hiding or hurt, but again no luck:( Thats why i am asking to see for a future update if their could be a soldier model with a weapon (or two if thats fine) that shoots like a normal person and can knife and throw different kinds of grenades. Thank you, but other than that works great!
     
  36. jchapman723

    jchapman723

    Joined:
    Jan 27, 2014
    Posts:
    27
    Much of what you requested can already be achieved with this asset. You just have to invest the time and effort to learn how to do it. You can't expect an asset to do all the work for you. You may have to do some extra coding or work with Playmaker to add extra complexity as well.

    If you couldn't even get your models to work then you probably didn't try hard enough.
     
  37. eliteslayer

    eliteslayer

    Joined:
    May 12, 2013
    Posts:
    64
    Im aware and ive tried and tried but have failed, further more the health system doesnt seem to work with other kits and the AI never dies but the player does. Anyway i know and once more i spent hours trying to figure it out but have not gotten it :( Which is why i am asking for help in such a way, i would never ask without trying myself first.

    And also i did try very hard for my models, but they glitch and bug out
     
  38. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Everyone,

    We've just released the latest version of AI Behavior (v 1.9). In the latest version there are quite a number of fixes and some new features thanks to a few different folks writing to me about their needs. Some features include a new audio trigger and an off mesh link trigger and state that can be used in conjunction with each other. There's a lot more than just that, so click on the version number on the asset store page to see the latest release notes.

    While I'm fairly confident it will be a smooth upgrade, make sure you have a backup of your project before doing so, just in case :)

    If you have any issues, please use the Contact Us menu option since I tend to not check the forums too often anymore.

    https://www.assetstore.unity3d.com/en/#!/content/3442

    @eliteslayer I'll see if I can add in a scene with the bootcamp demo soldier in the next update.

    Thanks,
    Nathan
     
  39. Teirdalin

    Teirdalin

    Joined:
    Nov 7, 2013
    Posts:
    4
    I'm actually having the same issue as yoshi stated earlier; now it might just be that I'm incredibly tired while trying to work on my project; but is there a proper process for getting mecanim; or any animations really, to work with astar? Or would I need to manually make a fix for that?
     
  40. mhmoudko

    mhmoudko

    Joined:
    Mar 24, 2015
    Posts:
    3
    i followed the tutorial :

    but it's not moving ( only displaying the following animation but the enemy doesn't move to the player ) ... and there's an error : "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    plz help ... im new :)
     
  41. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    The error tells you exactly what's wrong: you need a NavMesh.
     
  42. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    This is probably a tiny bit tricky at first when you don't know where everything is, but the nice thing is that it's really simple once you do.

    1) Make sure the GameObject(s) that you want to be navigated has the "Static" box checked. It's at the top right of the Inspector.
    2) Choose the "Window > Navigation" menu option.
    3) In the Navigation tab/window that opens up choose Bake.

    That should be it :)
     
    mhmoudko likes this.
  43. mhmoudko

    mhmoudko

    Joined:
    Mar 24, 2015
    Posts:
    3
    tried what u said , but still the problem is not solved ...

    here's the steps i followed from the beginning :

    1- Imported the AI behavior Asset
    2- Placed a plane
    3- Placed a FirstPersonController ( the tag is Player )
    4- Dragged a (avatar_complete.prefab) to the scene
    5- added a trigger (WithinDistance) to the idle state to change to follow state ( and adjusted the distance )
    6- checked the static box for the avatar_complete object , and a msg said do u want to apply to childrens ? i clicked yes ....
    7- went to the navigation menu ... clicked bake ( is there's a thing supposed to happen when i click it? )

    still there's an error :
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    and the avatar_complete is animating but not moving/following the player

    should i modify something to the navmesh ? ... there's a navmesh added automatically with the avatar_complete object .... or should i also add a navmesh to the player ?

    and thanks :)
     
  44. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    You're very close...

    The one that should be marked as static is the Plane in your scene. Static means that the object will never move (IE the ground, a building, trees, etc). So the avatar_complete should 'not' be static since it will move, but the plane should be static.

    Try that and then rebake... and let me know how it goes :)
     
    mhmoudko likes this.
  45. mhmoudko

    mhmoudko

    Joined:
    Mar 24, 2015
    Posts:
    3
    YESSSSS :D :D

    IT WORKED :D

    THANK U SO MUCH :D ... !
     
  46. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    No problem, glad I could help :)
     
  47. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    57
    no idea if this will get answered or not but im trying to figure out how to spawn a ai in an still use the way point system every thing else works when spawning but i cant get the way points t o work when setting them on spawn.
     
  48. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Wtyson, you'll need to go through one of the two SetPatrolPoints methods on the particular PatrolState. In one you pass the parent transform of the waypoints, for the other you can pass your own waypoints array. In the SetPatrolPoints where you pass the parent, it will sort your patrol points by name.

    I'm assuming you have a reference to the root AIBehaviors component (called 'ai' in the following example), so the code would look something like this:

    Code (csharp):
    1. PatrolState patrolState = ai.GetState<PatrolState>();
    2. patrolState.SetPatrolPoints(newWayPointsParent);
    3. // or
    4. patrolState.SetPatrolPoints(newWayPointsArray);
     
  49. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    57
    So im not the best coder in the world at all but i tried to modify your setpatrolpoints script to pull the gameobject fromt he scene but having issues on how to go about it since i need to get the transform of the object an store it then set it back...

    heres what i got going

    Code (CSharp):
    1. using UnityEngine;
    2. using AIBehavior;
    3.  
    4. public class SetPatrolPoints : MonoBehaviour
    5. {
    6.     public Transform patrolPoints;
    7.  
    8.     public GameObject waypoint;
    9.  
    10.     public Transform waypointtransform;
    11.  
    12.  
    13.     void Awake ()
    14.     {
    15.         AIBehaviors ai = GetComponent<AIBehaviors>();
    16.  
    17.         PatrolState state = ai.GetState<PatrolState>();  
    18.  
    19.         waypoint = GameObject.FindGameObjectWithTag("random wandering");
    20.  
    21.         waypointtransform = waypoint.gameObject.GetComponent(Transform);
    22.  
    23.         patrolPoints = waypointtransform;
    24.  
    25.         state.SetPatrolPoints(patrolPoints);
    26.     }
    27. }
    if anyone can help me with this that would be great thanks...
     
  50. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    57
    heres a modifided version of the setpatrolpoints script that will allow spawning an the getting of the waypoint group... tested an works flawlessly...


    Code (CSharp):
    1. using UnityEngine;
    2. using AIBehavior;
    3.  
    4. public class SetPatrolPoints1 : MonoBehaviour
    5. {
    6.     public Transform patrolPoints;
    7.    
    8.     public GameObject waypoint;
    9.    
    10.     public Transform waypointtransform;
    11.    
    12.    
    13.     void Awake ()
    14.     {
    15.         AIBehaviors ai = GetComponent<AIBehaviors>();
    16.        
    17.         PatrolState state = ai.GetState<PatrolState>();  
    18.        
    19.         waypoint = GameObject.FindGameObjectWithTag("random wandering");
    20.        
    21.         waypointtransform = waypoint.GetComponent<Transform>();
    22.        
    23.         patrolPoints = waypointtransform;
    24.        
    25.         state.SetPatrolPoints(patrolPoints);
    26.     }
    27. }