Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AI Behaviors Made Easy! (Walker Boys)

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

  1. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi Again,

    I have manage to set a follow state to the enemy character, however I play the state I can see that the enemy do run (on the same place) and not moving toword my player controller, why is that's happening?

    I'm using the navmesh with Unity pro where I bake the navmesh using unity pro 4.

    Please advise
     
    Last edited: Mar 29, 2013
  2. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    How can I have the AI move around randomly until something triggers another state?
     
  3. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hello derkoi,

    I believe you need to have a portal state and define some waypoints where he can move between them randomly, if you check the portal video you will get a better idea, on how to reach that.
     
  4. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Thanks, I'll check that out.
     
  5. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hello Walker boys,

    The problem of not being able to move is that the baked navmesh paramters was causing the problem, actually I was using baking the navmesh using the defualt values, however when I change the values to the same values exist on the example scene the problem get solved.

    what I recommend for walkerboys is to have a suggested values for the baking, or even referance a nice tutorial for baking the navmesh, or even have a debug system to know the reason of the problem.

    Thanks.
     
  6. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Can this work with 2D Smooth Moves animations?
     
  7. Mementos

    Mementos

    Joined:
    Sep 25, 2012
    Posts:
    79
    What has changed in 1.3.8? =)
     
  8. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,418
    Before buying I would like to know some things, i hope you don't mind:

    - Is this compatible with mobile Plattforms (iOS and Android?)
    - Will it work with 2D Sprites // compatible with 2D Frameworks (Uni2D, 2DToolkit, ex2D, SmoothMoves etc.)
    - are there PlayMaker-Actions?
     
  9. NathanWarden

    NathanWarden

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

    The main change is pretty big and I came onto our thread to announce it. We've added in nested triggers, so now instead of having just single triggers that handle a state change, you can now have multiple triggers/conditions by which a state is changed.

    Here's a very basic example...

    Before you could have a setup like this:

    - If a player is beyond 20 game units switch to patrol state

    Now you can have something like this:

    - If a player is beyond 20 game units
    -- AND if a player is within 30 game units switch to patrol state


    Hi Mayhem,

    1) Yes, it's compatible with all platforms.
    2) It will require a tad of programming on your side to plug it into whatever system you'd like, for animation, what you'll want to do is to is take a look at the "AIBehaviorsCharacterAnimator.cs" script. The default AI setup has this script on it, you'll need to make your own that has the "public void OnAnimationState(AIBehaviorsAnimationState animState)" method. It doesn't have to have OnAnimationState as the method name, but it does need to have the AIBehaviorsAnimationState as the parameter. Here is where you receive the animation states that are being called. Final thing is to make sure that on your AI agent that this script is the one selected in the dropdown in its' inspector.
    3) No, we haven't implemented anything with playmaker in our AI system.

    Thanks guys, hope I've answered your questions,
    Nathan
     
  10. eriihine2

    eriihine2

    Joined:
    Mar 16, 2013
    Posts:
    8
    In AIBehaviours.cs the GetClosestPlayer function is not working properly with multiple player tags. It returns the last player in playerTransforms within sightDistance but not the closest player within sightDistance.

    To workaround this I added if(targetDifference.sqrMagnitude < squareDistance) check to GetClosestPlayer which seems to solve the problem.

    Code (csharp):
    1.     public Transform GetClosestPlayer(out float squareDistance)
    2.     {
    3.         float sqrSightDistance = sightDistance * sightDistance;
    4.         int closestPlayerIndex = -1;
    5.  
    6.         squareDistance = Mathf.Infinity;
    7.  
    8.         for ( int i = 0; i < playerTransforms.Length; i++ )
    9.         {
    10.             Vector3 playerPosition = playerTransforms[i].position;
    11.             Vector3 targetDifference = playerPosition - thisPos;
    12.  
    13.             // is the target within distance?
    14.             if ( targetDifference.sqrMagnitude < sqrSightDistance )
    15.             {
    16.                         if(targetDifference.sqrMagnitude < squareDistance){
    17.                     squareDistance = targetDifference.sqrMagnitude;
    18.                     closestPlayerIndex = i;
    19.                 }
    20.             }
    21.         }
    22.  
    23.         if ( closestPlayerIndex == -1 )
    24.             return null;
    25.         else
    26.             return playerTransforms[closestPlayerIndex];
    27.     }
    Also it would be nice if checkForNewPlayersInterval could be edited via the Unity editor (as this is public property and hard to find otherwise). Currently this property is not visible in editor.
    Code (csharp):
    1. public float checkForNewPlayersInterval = 0f;
     
    Last edited: Apr 25, 2013
  11. KenOnion

    KenOnion

    Joined:
    May 1, 2013
    Posts:
    2
    How to use "cooldown" and "reload" of the AttackState? It does not seems to be working properly...
    e.g. I try to set ReloadAnimation value to "Combat", but the animation has not change on reload time.
     
    Last edited: May 1, 2013
  12. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Just wondering if any progress has been made with Mecanim ??

    note: I see "Rain Indi " Ai system now supports mecanim .... ( free on the asset store. )

    Sure hope Ai Made Easy is now working with mecanim.... its critical to any serious character design animation pipeline.
     
    Last edited: May 8, 2013
  13. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi SteelMatrix, I'm not sure why the cooldown options aren't working for you. The reload options will be removed in the next version since they weren't working. What you'll want to do instead is to have AI Behaviors switch to an idle state after attacking that has the reload animation on it.

    Hi Banksy, I made some headway on this yesterday. My primary reluctancy to include Mecanim has been the fact that I have to force everyone using AI Behaviors to only be able to use it with Unity 4. But, I think Unity 4 adoption should be high enough now that it isn't an issue for most people.
     
    Last edited: May 9, 2013
  14. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Would like some help please.

    I'm trying to spawn enemies from prefabs but every time I spawn one they don't remember the patrol points object so throw lots of errors when spawned.

    How can I get them to work please?
     
  15. NathanWarden

    NathanWarden

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

    It's pretty simple to handle this, you need to assign the patrol points at spawn time. Use the following code as a reference:

    Code (csharp):
    1. public class AISpawner : MonoBehaviour
    2. {
    3.     public GameObject aiPrefab;
    4.     public Transform patrolPointsParent;
    5.  
    6.     void SpawnNewAI()
    7.     {
    8.         GameObject newAI = Instantiate(aiPrefab) as GameObject;
    9.  
    10.         newAI.GetComponent<AIBehaviors>().GetState<PatrolState>().SetPatrolPoints(patrolPointsParent);
    11.     }
    12. }
    Let me know if you need additional help with this :)
     
  16. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Thanks for the reply. However I use playmaker Pool Manager for some reason I can't get it to work.

    Is there a way to add a script to the enemy object that searches for the Patrol points object when it's spawned?

    Thanks
     
  17. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Please help with the above as I can't get it to work. Thanks
     
  18. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi derkoi, I'm really not too familiar with either Playmaker nor Pool Manager. Could you possibly place a script on your AI prefab itself so when it spawns it looks for the patrol points. If you have only one patrol points group, you could search for it by tag. IE:

    Code (csharp):
    1. GameObject patrolPoints = GameObject.FindWithTag("PatrolPoints");
    If you have more than one and need to get specific ones for specific AIs. You could just look for the patrol points by the object's name, but use that as little as possible, because GameObject.Find is one of the slowest methods in Unity.

    Code (csharp):
    1. GameObject patrolPoints = GameObject.Find("PatrolPointsGroup1");
    Sorry I can't help you out in detail with regard to Playmaker and Pool Manager, but let me know if the above doesn't help you out and we'll try and find another solution.
     
  19. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Thanks, that would work, but how do I set the patrol points on your patrol script from a script I add to the AI prefab? With just the line you wrote or a more code? Sorry I really suck at code, hence why I use Playmaker.
     
  20. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi derkoi, No problemo, haha :)

    So, you should just be able to put the following script onto your AI prefab:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class FindAndAttachPatrolPoints : MonoBehaviour
    4. {
    5.     void Awake()
    6.     {
    7.         GameObject patrolPoints = GameObject.FindWithTag("PatrolPoints");
    8.  
    9.         if ( patrolPoints != null )
    10.         {
    11.             gameObject.GetComponent<AIBehaviors>().GetState<PatrolState>().SetPatrolPoints(patrolPoints.transform);
    12.         }
    13.     }
    14. }
     
  21. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Awesome, thanks. That works a treat!
     
  22. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Awesome derkoi, I'm glad it worked for you :)
     
  23. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Hi again Nathan,

    I'm having trouble understanding how to damage my player other NPC objects with the melee attack. I have the example script on the enemy and I've selected the attack method but I don't know how to write a script that sends a message to the object being attacked.

    Here's what I have I can see from the debug log that it's working:

    Code (csharp):
    1. public void OnAttack(AIBehaviors_AttackData attackData)
    2.     {
    3.         Debug.Log ("Melee attack");
    4.     }
     
  24. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    edit: I updated Unity and that seems to have fixed the problems.

    Something has gone horribly wrong with this package. I've suddenly started getting some errors that stop it from working at all. Even projects where it worked fine a couple of days ago and I haven't touched are getting these errors. Started a new project to check and it still is happening. What could be causing it? The only thing that I can think of that has changed is I installed Steam and Skyrim on my computer since the last time I knew it was working. Could one of those programs be interfering? I haven't updated Unity since the last time it worked and I restarted my machine.
    When I look at the avatar complete prefab I can see that behaviors are missing. They are jsut gone. Everything below Seek is empty. I tried to add them back in, but it kept reverting back to this.
    Here are the errors I am getting:


     
    Last edited: May 29, 2013
  25. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi derkoi, in the next update the attackData struct will have a target variable which will be the transform of the object being attacked. It will also have an attackState variable that will be a reference to the state calling the attack. So, in case you have multiple attack states calling the same "OnAttack" method you can determine which attack is the one that is currently active. I would still advise against that and use separate methods for clean code and performance reasons, but it does leave that option open if anyone wants to go that route.

    The next update should be out in a few days.

    Glad to hear that fixed it Drew :)
     
  26. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    AI Behaviors 1.4.1 is being uploaded for review as I write this :)

    Also, if you missed it, the previous update included nested triggers which we hope to have a video up explaining how to use them shortly

    AI Behaviors now requires you to use Unity 4 because we are working toward making it compatible with Mecanim. Some of the early alpha assets are included, but the next major update will likely include Mecanim support

    Here are the latest changes from the release notes for the version in review

    =================================================
    Version 1.4.1
    =================================================

    *** Now Requires Unity 4 ***

    Improvements:
    -----------

    Added a target and the attacking state into the AttackData structure.
    Attack is now a virtual method that can be overridden if the AttackState is derived from.
    The Attack state has a new reload system since the old one was broken. Now once it reaches a certain number of attacks it will change to whatever state is chosen. It chooses the attack state it comes from by default until one is chosen.
    There is now some initial ground work for getting Mecanim working.

    Fixes:
    -----------

    Fixed a bug where GetClosestPlayer was using sqrSightDistance instead of sqrDistance.
    Fixed a bug with the animation code sample.
    Added a flag for if a class has movement options or not (for editor code).
     
  27. Player2D

    Player2D

    Joined:
    Feb 2, 2013
    Posts:
    50
    hi.
    help me please.
    2.5d game. I need to pre-attack model initially rotated to the player(target) and then shots.
    I did it: Detection player(target) and immediately shots. model turns around and shoot all the time in the void.
     
  28. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi,
    I can't upgrade as the AssetStore keeps saying "Needs Unity Upgrade to version 4.2"

    V4.2 has not been released, so you can't even install it now as it is disabled.

    Did you release this with a beta version of Unity or something?

    Please fix!

    ty!
     
    Last edited: Jun 16, 2013
  29. Xander-Davis

    Xander-Davis

    Joined:
    Apr 23, 2011
    Posts:
    441
    I get the same message. Wanted to import it today. Help?
     
  30. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Asset store confirmed it's been uploaded with 4.2 beta which they should not have done. Guidelines will be updated to highlight this.
    Up to walker boys to regenerate and resubmit I think.
     
  31. Xander-Davis

    Xander-Davis

    Joined:
    Apr 23, 2011
    Posts:
    441
    Can Unity revert it in the Store until the Walker Boys fix?
     
  32. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Unsure. I'm *ASS*uming that asset store build uploads are done by the developer, which means they would need to regen the project on their side, unless AssetStore is able to reimport into 4.1.5 and rebuild...but that's work for them!
     
  33. Profocus

    Profocus

    Joined:
    Jun 16, 2013
    Posts:
    6
    Looks really good and I'll likely buy it, but I don't care for the way the agent "slides" around a waypoint in hard turns in the patrol video. Is this due to it being locked to the path? If you uncheck lock to path, will his heading remain true in that turns are natural? Other than that, it looks like a great system.
     
  34. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Hi. I'm trying to make a one-off attack that uses a leap attack that closes the distance to the player and then goes into normal melee attack. I tried to use an attack state with a high movement speed, figuring it would be just a matter of setting the right speed to close the distance but when it comes time to do that, he performs the leap attack with no forward speed. Any thoughts?

    edit: got it. Seem to have had some errors in unrelated code that was causing the problem.
     
    Last edited: Jul 1, 2013
  35. NathanWarden

    NathanWarden

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

    Sorry it has taken me a while to respond, I've been away in a developing country with very slow internet for the last three weeks or so. Anyway, the package has been resubmitted with Unity 4.1.5 instead of 4.2 beta. I'm deeply sorry for anyone this has caused issues for. Unity usually accepts our updates very quickly, usually within a day or so. However this is up to Unity and I can't guarantee that.

    Thanks for your patience,
    Nathan
     
  36. BuildABurgerBurg

    BuildABurgerBurg

    Joined:
    Nov 5, 2012
    Posts:
    566
    Hello Nathan,

    Could you pm me when you get this working with mecanim.

    I will purchase if it works with mecanim.

    Keep up the good work
     
  37. Infernomaster

    Infernomaster

    Joined:
    Jan 20, 2013
    Posts:
    16
    hey, got a problem .. all of a sudden the option in melee attack, where min and max distance to attack is defined, has dissapeared. Is this because of the new update? I looked @ the code and there doesn't seem to be any references left, but the docs say otherwise ??? Im confused!

    Ohhh and is there some option to get the current state of an enemy to be printed to the debug log (I'm not that good with coding)
     
    Last edited: Jul 24, 2013
  38. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Same problem here...
     
  39. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    Hi i have a question about this package, how does it work on IOS devices?and with a pathfinding solution?
     
  40. eriihine2

    eriihine2

    Joined:
    Mar 16, 2013
    Posts:
    8
    Is this package still maintained for unity 4.2?

    I'm trying to add new custom states and get following errors:

    ArgumentOutOfRangeException: Cannot be negative.
    Parameter name: length
    System.String.Substring (Int32 startIndex, Int32 length) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System/String.cs:348)
    AIBehaviorsComponentInfoHelper.GetNameFromType (System.String typeString) (at Assets/AIBehavior/Plugins/AIBehaviorsMadeEasy/EditorHelpers/AIBehaviorsComponentInfoHelper.cs:236)
    AIBehaviorsEditor.OnInspectorGUI () (at Assets/AIBehavior/Editor/AIBehaviorsMadeEasy/AIBehaviorsEditor.cs:188)
    UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty)
    UnityEditor.PopupCallbackInfo:SetEnumValueDelegate(Object, String[], Int32)


    ArgumentOutOfRangeException: Cannot be negative.
    Parameter name: length
    System.String.Substring (Int32 startIndex, Int32 length) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System/String.cs:348)
    AIBehaviorsComponentInfoHelper.GetNameFromType (System.String typeString) (at Assets/AIBehavior/Plugins/AIBehaviorsMadeEasy/EditorHelpers/AIBehaviorsComponentInfoHelper.cs:236)
    AIBehaviorsEditor.OnInspectorGUI () (at Assets/AIBehavior/Editor/AIBehaviorsMadeEasy/AIBehaviorsEditor.cs:188)
    UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty)
    UnityEditor.PopupCallbackInfo:SetEnumValueDelegate(Object, String[], Int32)


    My custom state is basically the skeleton state renamed that you have in the package.

    Also AI behaviours menu is totally missing in unity 4.2 (used to be under components...)
    edit: got the menu back after reimporting the AI behave

    ???
     
    Last edited: Aug 12, 2013
  41. Asmina

    Asmina

    Joined:
    Jul 22, 2013
    Posts:
    112
    Set the movement speed on the "Melee Attack" to zero. Or zero.1 Temporary fix :3
     
  42. Nick_O

    Nick_O

    Joined:
    Jul 13, 2012
    Posts:
    5
    Hi,
    Is it possible to change the patrol waypoints group during gameplay? I'm looking for an NPC to patrol a set of objects that gets collected by the player. So as each object gets collected it is taken off the patrol set of waypoints. I'm using JS but I'm not sure how to stop the patrol, change waypoints set and restart the patrol.
     
  43. NathanWarden

    NathanWarden

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

    Yes, it is possible. First, in order to use JS you need to place the "AIBehavior/Plugins/AIBehaviorsMadeEasy" folder into the "Plugins" folder. This way it gets compiled first, otherwise it will throw an error.

    The code to update the patrol points would look something like the following:

    Code (csharp):
    1. var aiAgent : AIBehaviors;
    2.  
    3. function UpdatePatrolPoints(patrolPointsParent : Transform)
    4. {
    5.      var patrolState : PatrolState = aiAgent.GetState.<PatrolState>();
    6.      patrolState.SetPatrolPoints(patrolPointsParent);
    7. }
    You can destroy or disable the transform for the waypoint your character collects, then simply call the above code where "patrolPointsParent" is the parent transform of your patrol points.

    Does this help answer your question?

    Thanks,
    Nathan
     
  44. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
  45. Nick_O

    Nick_O

    Joined:
    Jul 13, 2012
    Posts:
    5
    Nathan, thanks a load for the support. That got it working just the way I wanted. Cheers, Nick
     
  46. MrCocopuffz

    MrCocopuffz

    Joined:
    Feb 27, 2013
    Posts:
    9
    I purchased A.I. Behavior and have been experimenting with it. I've noticed it has very basic navigation built in but it doesn't navigate around newly placed object like a tower defense type of behavior when I place a block in front of the avatar he walks right through. Is this where A* comes into play. I don't have Unity Pro. So far I've been very impressed with everything this asset has to offer.
     
  47. CaptainChristian

    CaptainChristian

    Joined:
    Apr 3, 2013
    Posts:
    100
    Hi,

    I just imported your asset into a new project. Unity reports several scripts to be missing in most of the ai specific prefabs. Please fix it.
     
  48. cmonroy

    cmonroy

    Joined:
    Sep 10, 2013
    Posts:
    8
    Must be missing something trivial because I can follow the tutorial steps and everything works correctly, but when I start with my own character no animation comes out. I'm following these steps:

    1. Import my FBX character, rig it as humanoid and save it
    2. Create a scene with a plane and some lighting
    3. Select the character and add the AI component: AI Behaviours Default Setup
    4. Create a Nav Mesh

    Now comes the fun part... Sample characters don't have an Animator component so I remove it from mine (auto included when FBX was imported and rigged as humanoid).

    5. Make a couple of Animation States: Idle and Walking, deactivating the others
    6. Hit Play and got this warning: No animation component found for character object or child objects...

    So, I add an animation component... But after playing a bit with this, I come to the conclussion that I am missing some part of information that is probably too "common sense" to make it explicit.
     
  49. NathanWarden

    NathanWarden

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

    It looks like your issue is because you're importing a character with a Mecanim rig, which we don't officially support... yet. This will be supported sometime shortly after 4.3 is released (because 4.3 includes some functionality that falls inline with how our system works). So, Mecanim support will be available soon.

    You'll need to set your Rig to Legacy instead of Humanoid and use the Legacy animation system.

    Let me know if you're still having trouble.

    Hope this helps you,
    Nathan

     
  50. cmonroy

    cmonroy

    Joined:
    Sep 10, 2013
    Posts:
    8
    Perhaps what it is happening is that I was trying to use your animations with my character... For what I understand you are saying, Legacy animations can be converted to Humanoid and retargeted if using an Animator component, but then AI Behaviours won't do its magic. On the other hand, if I just rig my character as legacy I won't be able to use your animations either :) which corresponds to what happened.

    Thanks Nathan.