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
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

AI Behaviors Made Easy! (Walker Boys)

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

  1. zappapa

    zappapa

    Joined:
    Dec 12, 2010
    Posts:
    57
    It's been a week since you posted this, Nathan. Please let us know when we can view the video's with the new features.
     
  2. profcwalker

    profcwalker

    Joined:
    May 3, 2009
    Posts:
    243
    Hi,

    Just want to let you know we've got a new training video up showing the steps for implementing a new State and Trigger to the AI Behavior, so that you can easily create new ones. It's a great watch and will certainly help in your development process.
    Let us know if you have any questions about it. Thank you.

     
  3. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Stephane,

    Yes, our system can definitely handle your needs. One point is not immediately available and the other is irrelevant.

    Not available:
    -Priority based attacks (eg some units are more important to kill than others)
    * You'd need to probably write your own trigger for this as priority is not one of our current features.

    -NPC Avoid obstacles
    Since our system relies on external pathfinding systems, it is up to the pathfinding system to handle obstacle avoidance. If you are using Unity Pro, our system works seamlessly with the internal Unity Nav system and will almost certainly work automatically with anything else they add to it.
     
  4. dabrow

    dabrow

    Joined:
    Nov 15, 2010
    Posts:
    22
    Thanks for video
    Cheers
     
  5. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,052
    Is it possible to make triggers and states with Javascript. I hope it is :)
     
  6. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Nuverian,

    I haven't tried it, but it will probably work if you move AI Behaviors into the Plugins folder.
     
  7. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    What components are needed on the object to fully have the AI and Behaviors working? So far I followed the setup process and also added the AIPath component but I think I need some kind of AIResponder component.
     
  8. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    224
    It's as easy as copy/paste... This script even sets up the target and points to it from the AI component automagically, so you don't even need to create one manually... (assuming you're using the free AStar pathfinding?)
    Create a C# script called "AI_PathResponder", and put the following script in it, and attach to your AI:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class AI_PathResponder : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     AIFollow follower;
    9.     void Awake()
    10.     {
    11.         target = new GameObject().transform;
    12.         target.name = "TARGET_"+name;
    13.         AIBehaviors ai = GetComponent<AIBehaviors>();
    14.         ai.externalMove = OnMove;
    15.         follower = GetComponent<AIFollow>();
    16.         follower.target = target;
    17.     }
    18.     void OnMove(Vector3 targetPoint, float targetSpeed, float rotationSpeed)
    19.     {
    20.         target.position = targetPoint;
    21.         follower.speed = targetSpeed;
    22.         follower.rotationSpeed = rotationSpeed;
    23.     }
    24. }
    25.  
     
  9. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    @danreid70 that's what I did, I actually followed your instructions from the previous page but shouldn't AIPath be used instead AIFollow? And yes, I am using the free version of the A*.

    I have the object to idle when no players are around and follow on line of sight but when I play the scene I get an error when I get in sight of the object and the scene slows down badly.

    Do I need to specify a target with the responder script?
     
    Last edited: Aug 14, 2012
  10. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Unicron,

    Have you taken a look at our video of us setting up Astar with our system. Hopefully that will give you a better understanding of what is needed.

    http://www.youtube.com/watch?v=Gz1X8PYfp1g
     
  11. paperchief

    paperchief

    Joined:
    May 30, 2012
    Posts:
    8
    I am not very clear on how to create a level mesh and where this navigation tool is. Any help is greatly appreciated. :D
     
  12. paperchief

    paperchief

    Joined:
    May 30, 2012
    Posts:
    8
    I am not very clear on how to create a level mesh and where this navigation tool is. Any help is greatly appreciated. :D
     
  13. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    224
    @Unicron: I got tied up the last few days and haven't gotten online at home yet - tonight or tomorrow after work, I'll screencap my AI bot setting to show you what I have connected to my AI "agent". I have to think back and remember how I originally set it up - I think you also have to attach the "Seeker" script from the AStar pathfinding project to your agent. The script I posted was a slightly modified one from the video tutorial from Walker Boys - I went to the AStar website and followed their tutorial for setting up the AStar pathfinding, first, and then the Walker Boys tutorial - it went very well and worked right off the start, so I bet there's just one script or component that you're missing. If you can, before I get online after work, go through both of those tutorials, and I bet you'll find the one piece that's missing. It's very well worth going through both AStar's tutorial and Walker Boys video - VERY informative and well done! Let me know if you got it working or I'll post more later on. I really like this system, and once you have it set up and tweak AStar, you'll see how powerful it is!
     
  14. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi paperchief, if you're using Unity Free you won't have a the Navigation system as that's Unity's built in Pro only nav system. You can use Aron Granberg's Astar Pathfinding system (which has a free or payed version) as a nice alternative instead :)

    http://www.arongranberg.com/unity/a-pathfinding/
     
  15. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Is it possible to create different "Within Distance" triggers that responds to certain types of sound clips and or animations?

    For instance, I'd like to have a "Within 10m Distance" trigger that looks for the "avatar_walk01" sound clip or animation for example which then triggers the AI into "Seek" state. Is something like that possible?
     
  16. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Unicron,

    That is absolutely possible (and in my opinion a lot of fun). You can do the following to get started:

    1) Duplicate the WithinDistanceTrigger class
    2) Rename the new file and the new class to whatever suits your needs
    3) Add whatever properties to the script you want
    4) Adjust the Evaluate() method to your liking.

    Note that you probably want to completely delete the DrawInspectorProperties() method so that our system will draw all of the public properties you add automatically for you. That is, of course, unless you want to write your own custom inspector GUI code.

    I think that should be it, our system will handle the rest.

    Here's a video showing how to create your own custom triggers and states from scratch:

    http://www.youtube.com/watch?v=R7kD1hX_tIc

    Hope this helps,
    Nathan
     
  17. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Great, thanks for the help, I'll get started on that.
     
  18. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    So I'm trying to get an object to follow when they see the player when when they are in their line of sight. I have the AIFollow and AI_Path Responder that danreid70 provided but I get this when I hit player. I also have A* setup in the scene correctly with a grid graph.



     
  19. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    So I got everything all setup now, I got past the previous error and have the object follow patrol and randomly go into idle and what not and then follow the player when in line of sight. All peachy but I can't duplicate the object as it crashes Unity when I do, any insight on what could be the problem?
     
  20. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Unicron, I'd probably need to have the project itself to really track down what's happening to cause that and to know whether it's our system or Astar. Making sure your scene is saved, you could try and strip the astar components off of the Game Object and if it crashes then it's our system. If it doesn't crash then re-open your scene and strip off our components. If it crashes then you know it's the astar system.

    You can always try to upload it using Dropbox, Google Drive or some utility like that and share the link with us in an email by going to the menu: Component > AI > Report A Bug
     
  21. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    I think its with the AI Behaviors because I can duplicate just fine after removing its components from the object plus I can create multiple objects manually, longer process but it works, only duplicating crashes.
     
  22. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Unicron, I can't reproduce that on my end which means that if at all possible, if you can send me your project I'd be more than happy to track down any bug/issue we have in there and fix it. :)
     
  23. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    It's working fine now, I'm able to duplicate them. I just removed both the AIBehavior and A* folders in my project folder and re-imported them and works great!

    Now I'm working on creating that state that you helped me with previously. Thanks!
     
  24. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Glad to hear it, hope it's fun making those. :)
     
  25. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hey all,

    With the exception of one particular issue, it looks like AI Behaviors Made Easy works with Unity 4 without breaking.

    Here's the fix for the issue for anyone using our system and using Unity 4 beta... The following lines need to be changed in order for the GUI to work properly. We will put an update onto the asset store probably around the time Unity 4 is officially released to account for any changes.

    In AIBehaviorsAnimationStatesEditor.cs

    Code (csharp):
    1. change
    2. AIBehaviorsStyles styles = new AIBehaviorsStyles();
    3.  
    4. to
    5. AIBehaviorsStyles styles;
    6.  
    7. and then put the following immediately after the void OnEnable() method
    8. styles = new AIBehaviorsStyles();
    so it should look something like:
    Code (csharp):
    1.     AIBehaviorsStyles styles;
    2.  
    3.     void OnEnable()
    4.     {
    5.         styles = new AIBehaviorsStyles();
    6.         m_Object = new SerializedObject(target);
    and the following is how the AIBehaviorsEditor.cs should look

    Code (csharp):
    1.     AIBehaviorsStyles styles;
    2.  
    3.     void OnEnable()
    4.     {
    5.         BaseState[] states;
    6.         styles = new AIBehaviorsStyles();

    Hope this helps anyone on the Beta,
    Nathan :)
     
  26. KindalD

    KindalD

    Joined:
    Aug 24, 2012
    Posts:
    6
    Hey Nathan,

    I purchased AIBehaviors a bit ago and finally have the chance to sit down and mess with it more. I by no means am an accomplished coder which is partially why I purchased behaviors. I am running into a few problems.

    I noticed in your ranged attack video that your avatar would autoface its target. I know the system has been changed since then but I am having some issues. Is facing the target something that behaviors will still handle or will have to put in my custom attack script or am I doing something wrong?

    Also I have my firing and health system working but when the target dies while the cannon is in the attack behavior I get null reference errors. How can I access a Gameobjects current trigger target so I can throw a check in there? Should I just do a null check on the target or send some type of message letting behaviors know that target is dead?

    I am sure I will have a million more questions but those are the ones buggin me right now.

    Thanks in advance
    KindalD
     
    Last edited: Aug 24, 2012
  27. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi KindaID,

    Hmm, I'm not sure what's going on there. I just opened our demo scene and the AI is still tracking me. It shouldn't have anything to do with the attack component being called to, so you should be fine there.

    I'm also not sure why you're getting null reference errors. If it's possible to send me your project, you can use the "Component > AI > Report A Bug" and send us an email with a link to your project and I'd be happy to take a look at whatever error you're getting.

    I'm not sure if this is what you're looking for code-wise, but may come in handy in the future at least. You can get ahold of the triggers themselves by accessing the AIBehaviors scripts' states. There are three instance methods:

    GetState<T>(); // Returns the first state of Type T
    GetState(System.Type type); // Returns the first state of Type type
    GetStates(); // Returns all states

    Here's an example using the Generic method:

    Code (csharp):
    1. public class MyBehavior : MonoBehaviour
    2. {
    3.      AIBehaviors ai = GetComponent<AIBehaviors>();
    4.      AttackState attackState = ai.GetState<AttackState>();
    5.      Trigger[] triggers = attackState.triggers;
    6.  
    7.      foreach ( Trigger trigger in triggers )
    8.      {
    9.            if ( trigger is BeyondDistanceTrigger ) // Or whatever the desired trigger type is
    10.            {
    11.                  // Code Here ...
    12.            }
    13.      }
    14. }
     
  28. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Has anyone tried using AI Made Easy with Alex Kring's pathfinding tool? I AI Made Easy works with Path, Granbergs solution, but I'm interested in the other because it allows for dynamic changes at runtime. I'd like to have AI avoiding both other moving AI and moving objects in the scene as well. Not sure if Path can do this. There'sno indication in the demo for either the free or pro version. Thanks.
     
  29. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi tool55, I haven't tried it personally, but, if it supports programatically setting a navigation target, then the answer is yes, with a little bit of setup, they work together.
     
  30. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Thanks, Nathan. I went ahead and bought Kring's SimplePath. For 60 bucks I figured it's worth giving it a try. I'm sure targets can be set programatically. I'm not good with C# yet (better on Javascript but still not great), so I'll have to muscle my way through. As I mentioned, I like the fact that SimplePath performs dynamic pathfinding. His demos of dozens of AI navigating around moving objects is pretty impressive. Not sure about performance. Much appreciation for the insight.
     
  31. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hello!

    I have a quick question about the ranged attack behavior. How can I set which unit (or transform) a AI is supposed to shoot at?

    Thanks

    Stephane
     
  32. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Stephane,

    You set this by telling it what "Player Tags" it should be looking for. By default it will look for any object tagged as "Player". If there is a collider on your player object be sure to ignore the layer the player's collider is on by unchecking it in the "Visual Obstruction Layers".

    Please let me know if you need any additional help.

    Hope this helps you Stephane,
    Nathan
     
  33. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hello Nathan,

    Yes I did that and the AI is shooting. The problem I have is that it does not rotate toward the enemy. I am not using NavMesh but PathFinding. This could be the issue?
     
  34. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Yeah, unfortunately there was a bug in that release with 3rd party nav systems that causes the AI not to turn. This bug hads been fixed and will be updated in the next release.
     
  35. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    When do you expect to provide a next release?
     
  36. pinchmass

    pinchmass

    Joined:
    Jul 2, 2012
    Posts:
    156
    yer any new goodies on their way
     
  37. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hey guys,

    Hopefully, we will get a new release submitted to the asset store today.

    It only has two real changes which are:

    1) The bug has been fixed where AI's wouldn't rotate when using a 3rd party nav system.
    2) It should now work with Unity 4 beta 7

    The next major release will probably be several months away since we are all working on some other projects right now.

    Have a great day,
    Nathan
     
  38. paperchief

    paperchief

    Joined:
    May 30, 2012
    Posts:
    8
    I have just realized that the ai only shoots rotates to the left and right to shoot, is there any way i can make the launchPoint rotate 360 degrees to shoot instead of shooting only to the left and right?
     
  39. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Hello, I'm interested in your 2D solution. Like it appears in the presentation imagem. Image attached.
    $Sem título.png

    With your AI, I can make a copy of the behavior of this game? I need it for mobile.
    https://www.dropbox.com/s/4aid3hebmiq9c71/ss2.zip

    It's Stick's Soldiers 2, from Unlimited Whitespace. If you dont want to run my executable, you can download from the internet the game.

    I dont know how to do something like the AI of this game. I want that you run the game, and look at it, and say me if your system can help me to reach that.

    If positive, and you can help me to reach that, I will buy in the same second.
     
  40. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hi Nathan,

    Has the package been updated in the asset store? I don t see any change in the version. Is it me?
    If not, can you PM me the patch? thanks

    Stephane
     
  41. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Blaze,

    It will definitely work with that type of game. You would need to write some custom states, however, to account for the jumping and like actions that we don't have out of the box. I'm not sure what level you are with your programming skills, but, we've made it pretty easy to implement your own states. We've made the ability to create new states about as plug and play as you'll probably ever see in code. The video that shows how to make these can be found here:

    http://www.youtube.com/watch?v=R7kD1hX_tIc&feature=player_embedded


    Hi Stephane and anyone else,

    It looks like as of today the latest minor release has been accepted to the Asset store. This should have the 3rd party rotation bug fix and should also work with Unity 4.0 beta 7

    Enjoy,
    Nathan
     
  42. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    Right, create states isn't the problem.
    My problem, is how I can made it "know" where and when jump, to make the characters adapt to any level design.
    In the example (Sticks Soldiers2), it have a built in map editor. Then, the AI is not made by Waypoints and triggers in the map.
    The sticks "knows" how and when jump, and how to reach the enemy, how to kill it.
    My big problem is with the AI "idea", not the AI implementation.
    I need help to implement a "pathfind" for 2D, then use your behavior system, to make the sticks get life.
     
  43. kamakura1192

    kamakura1192

    Joined:
    Apr 1, 2012
    Posts:
    4
    I'm using AIBehaviors in unity pro.

    I want to make enemies in the sky.
    Are you able to let the "Patrol" to enemies that are flying high from ground obstacles?

    (I'm sorry, I use the translation google ...)
     
  44. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    How does this system perform on mobile? Any stats or videos?
     
  45. blaze

    blaze

    Joined:
    Dec 21, 2011
    Posts:
    211
    The support here is too much slow huh?
     
  46. NathanWarden_old

    NathanWarden_old

    Joined:
    Oct 4, 2005
    Posts:
    37
    Hi Blaze,

    To make it know when to jump you could probably implement some trigger boxes into your scene that will either change the state of the AI or you could have it override the AI systems' movement momentarily while it's jumping.

    There's really no need to implement a 2D pathfinding solution. If you need the characters to not do a true 3D rotation, you can probably just billboard them to the camera or force the y rotation on a sub-object that you're using as your sprite.


    You would probably need your flying AI to do a raycast to the ground every few frames or so and place a tagged object at the height of the ground where the raycast hit. There may be a better solution than this, but this is the first one that comes to mind :)


    I don't have any stats to give you accept for the ones from a few pages back in this thread. I can tell you this though, from my testing the main thing that eats up performance is Unity's "CrowdManger" system which takes up 80 - 90% of the CPU time (which we can't do anything about). Probably the next major thing is going to be the pathfinding system that you decide to use if you're going the 3rd party route (again we have no control over this). From all of my testing, we have a very low overhead (usually under 1% of the CPU time). So to answer your question... if your game can handle the CrowdManager or the 3rd party Pathfinding system, it can more than likely run with our system as well.

    Sorry about that Blaze, I do get kind of busy with other things I have to work on and this gets put slightly on the back burner. Again, I do apologize.
     
  47. runner

    runner

    Joined:
    Jul 10, 2010
    Posts:
    865
    PC Game. Download

    OSX Game Download

    $AI-Test 2012-09-23 03-15-17-08.jpg

     
    Last edited: Sep 28, 2012
  48. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Runner, that's pretty cool! I finally got a chance to sit down and check it out... very nice, has a lot of potential. Thanks for sharing :)
     
  49. runner

    runner

    Joined:
    Jul 10, 2010
    Posts:
    865
    Thanks,
    But there is a problem in the demo that when in Patrol state they get Hit. how to prevent the AI from sliding ? Not every-time but often they will do that. :(
     
  50. NathanWarden

    NathanWarden

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

    That was a bug that will be fixed in the next release where you'll be able to set movement speed to 0 on the GotHit state and it will stop the AI. What you could do for now is immediately after the GotHit state is called, call an idle state that will have the got hit animation on it (use a timer with a 0 time for an immediate state change). The idle state automatically sets the speed of the AI to zero.

    Hope this helps and please let us know if you spot any more issues or bugs.

    Thanks a bunch,
    Nathan
     
unityunity