Search Unity

AI Behaviors Made Easy! (Walker Boys)

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

  1. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Don't worry greatUnityGamer, I'm glad to help you.

    The best info is in that last manual in the Documentation folder, because it's the most updated.
    Keep looking also at the demo scenes it's the best way to see how the AI has to be set up in different situations.

    For navigation you just need a NavMeshAgent and bake the Navigation in the scene. If you want you can add colliders to different parts of the body of your character but that is not needed for the AI system.

    About your question saving prefabs, sure you can, just set up your AI, made a prefab and instantiate it as many times you want in your game.
     
  2. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I have a really strange issue happening with the latest version: for some reason, the AI ignores the player unless the AI is INSIDE a collider attached to the player and I have no idea how that's happening. Never happened before.

    edit: turns out if I uncheck "Find Visible Targets Only" it works fine. How is this checked? Could it because I am using a player with no visible mesh? I'm sure I've done that before. Oh well. Maybe that checkbox was unchecked there.
     
    Last edited: Feb 5, 2017
  3. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi @dpy , I have recently updated Unity to 5.5.1 and also updated AI Behaviour to 1.13. I must say you have added some fantastic features to this asset since I've last updated, thank you for these additions :)

    I do have a question about the FormationMovement and 12_state_fly scenes. This may seem obvious, but after dragging a rectangle around the AIs, what exactly will make them start moving in formation? I have tried pressing many different keys but they stay in the same position. Also for the flying scene there is an animation error when trying the scene. I have tried to fix it by adding an animation component and changing the clip in the settings, but the AI simply stays in the same spot.

    Not sure if this is due to my Unity version or if I'm doing something wrong. Please let me know because these two new features look very promising.
     
  4. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hello @drewradley ,
    If it was because of the "find visible targets only" option that was checked it is because somehow the AI wasn't "seeing" the player, this option uses a raycast checking for a GameObject tagged with the specified tag ("Player" as default)
    That means that probably the GameObject where the collider was wasn't tagged as "Player".
     
    Last edited: Feb 9, 2017
  5. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hi @Hamesh81 thank you! ;)

    I'm sorry to tell you that the fly state isn't actually finished (thats also why its not in the release notes). I guess we shouldn't have included that scene in the package yet... :oops: I hope we can get it done for the next update

    About the formation moving after selecting the AIs just right clic somewhere in the scene, that should make them move. It's just a simple example how this can be done, it isn't actually something new for the system, it uses regular SeekStates to move the AIs to specific positions.
    On the camera you can find the 2 scripts that are used for that :)
     
    Last edited: Feb 9, 2017
  6. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    No problems @dpy . I'll look forward to trying it out when it is completed ;).

    I have tried out the formation scene and it is working as you have suggested. I even tried to place many obstacles around to break the AI's formation but they managed to reform perfectly. Great job on this addition, it works really well!
     
  7. Darkhitori

    Darkhitori

    Joined:
    Jan 7, 2015
    Posts:
    16
    Love the new Step Back State....How about adding A Side-Step/Dodge Left or Right State!
    Oh and by the way is it possible to add a Stamina/Mana System like the Health...that depletes and replenishes when using certain states(ex...AI runs after player but it's stamina runs out and changes to a idle tired state till it starts to replenish or when using melee attacks with different stamina cost).
     
  8. clamchoda

    clamchoda

    Joined:
    Jan 21, 2017
    Posts:
    11
    Hello, first of all thank you for this wonderful asset it is a real time saver. I figure it's better to ask my questions here so others can see a solution as well if needed.

    I am having two problems I am wondering if anyone has run into similar issues.

    1. AI's in large packs seem to push each other (rigid bodies, movement speed set to 0 in Attack State seem to have no effect)
    - You can reproduce this easily in a blank scene by setting up 20 Melee vs 1 Melee. As the 20 AI's surround the 1 Melee you can see this "Pushing" effect

    2. What is the correct way to trigger out of the attack state when the current target is dead? I need the AI to continue attacking other specified tags around him.

    Things I've tried;
    - The Dead State settings for Destroy Colliders on the current target doesn't seem to have any effect on Attackers Triggers.
    - The Dead State settings for Destroy Game Object (which doesn't seem to destroy the game object. I've been monitoring health in code and destroying it manually when health is less than zero). will actually work to break the Attack State of the Attacker but this is not desirable really. I want to see their slaughtered corpses on the ground!
    - In attempt to achieve that, I tried messing with the Dead State settings for Change tag.


    Currently, Attacker is looking for custom tag Enemy Tag. I use the Change Tag settings in the Dead State of the enemy to change his tag to DeadEnemy when he's dead.

    If Enemy Tag is Within Distance the Attacker will trigger Attack State, use Timed Trigger to switch back Idle State which begins attacking again when Enemy Tag is Within Distance. This works great.

    The problem is, even though when the enemy dies I can see the tag change from Enemy to DeadEnemy in the inspector, the Attacker still triggers his Attack State on the DeadEnemy tag after switching to Idle State and continues to beat a dead corpse.

    A more visual layout;



    Enemy, tagged Enemy
    Global Tags: Attacker

    Idle State -> Within Distance trigger Attack State
    Attack State -> Timed Trigger (time of attack) trigger Idle State
    GlobalTriger -> LowHealthTrigger less than zero trigger DeadState
    - DeadState properties Change Tag DeadEnemy




    Attacker, tagged Attacker
    No Global Tags

    * Idle State -> (Custom tag Enemy) Within Distance trigger Attack State *
    Attack State -> Timed Trigger (time of attack) trigger Idle State





    The problem lies here in the Attacker; Idle State -> (Custom tag Enemy) Within Distance trigger Attack State. Why does this trigger still fire and go into Attack State after the enemy has died and changed his tag to DeadEnemy?. (I verify in the inspector that it has changed)

    Thank you all for your time.
     
    Last edited: Feb 12, 2017
  9. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Thanks for your purchase :)

    This problem is actually due to how Unity's navigation system works. However, I'm unaware of any out-of-the-box way to keep the AI from going through to try and reach it's destination. If all you're concerned about is each AI pushing one another, you can turn the Quality setting under Obstacle Avoidance on the Nav Mesh Agent to "None". It won't push each of the AI's now, but will walk right through them.

    I would say you could stop other AI's by using a Nav Mesh Obstacle and turning "Carve" on, but that will probably keep that AI itself from moving :( I don't know if you've played StarCraft or not, but if you need behavior more like a siege tank this method would be perfect since you could just enable and disable the Nav Mesh Obstacle as needed, but I'm guessing that may not be what you're looking for.

    edit: I suppose if you just want them to stop, you could leave the avoidance setting at it's default, but maybe do collision detection between them. If one AI collides with the other you could call "GetComponent<NavMeshAgent>().SetDestination(transform.position)" which should stop the AI in place, or set the speed of it to zero. I wrote that code off the top of my head so it may contain mistakes.

    I usually use two global triggers... the first one being a CurrentState trigger and setting it to the Dead state. Also set the "Change to" to your dead state. Finally, enable "invert result". This will make it mean "if not dead".

    The second one would be nested inside of that trigger and would be a low health trigger and set it to 0.

    So if it isn't already dead and the health is less than or equal to 0 change to the dead state.

    It would look something like this:

    -- Global triggers:
    ---- CurrentState is Dead. Invert result. Change to: Dead state.
    ------ LowHealth set to 0

    Hope that helps,
    Nathan
     
    Last edited: Feb 12, 2017
  10. clamchoda

    clamchoda

    Joined:
    Jan 21, 2017
    Posts:
    11
    Great Unity Gamer, - A work around for your issue of him not rotating towards the target can be solved in your attack component. Just force AI to look at the current target it is attacking in C#.

    Something as simple as;

    Code (csharp):
    1.  
    2. public void MeleeAttack(AttackData attackData)
    3. {
    4.       gameObject.transform.LookAt(attackData.target);
    5. }
    6.  
    Will force him to look at his current target while attacking. (Melee attack is just the script you attached on your Attack state). Although this solution is kind of ugly and will be choppy looking every time he attacks. I just gave you a one liner so you could visualize the fix.

    Something like this will look much smoother;

    Code (csharp):
    1.  
    2. private static GameObject LookTarget = null;
    3. .
    4. .
    5. .
    6. if (LookTarget)
    7.   {
    8.   Quaternion lookAtRotation = Quaternion.LookRotation(LookTarget.transform.position - transform.position);
    9.   transform.rotation = Quaternion.Slerp(transform.rotation, lookAtRotation, Time.deltaTime);
    10.   }
    11.  
    12.  
    Sorry if this doesn't format right, I'm new around here guys.
     
  11. clamchoda

    clamchoda

    Joined:
    Jan 21, 2017
    Posts:
    11
    AI works great for Single Player vs AI scenarios.
    Is the AI not intended for use with Multiplayer VS AI scenarios?

    The issue with multiplayer vs AI is the AI changes the attack.target during the attack . This causes the Melee AI to apply his attack to any visible random target around him instead of his current target.

    Scenario:
    Player A and Player B VS AI.
    Player B is withing melee range of AI, Player A is out of melee range but within visibility range.

    Problem
    1. AI current target Player B.
    2. AI is within melee distance of Player B, so he attacks the current target
    3. While AI is attacking player B, AI changes current target to Player A (even though he is not within melee range, but within distance).

    You can reproduce this issue in a blank scene, using just the default scripts provided with the AI. Although, it will most likely only be noticeable in big packs over time. Give player B 1000000 life or something, and you can watch the life of player A randomly decrement as the AI attacks player B.
     
  12. clamchoda

    clamchoda

    Joined:
    Jan 21, 2017
    Posts:
    11
    Any luck or update on the multiplayer bug, or is this AI just not intended for AI vs multiplayer scenario? I emailed a blank scene demonstrating the bug to your team last week. Please let me know if it's been lost
     
  13. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hello @clamchoda, I tried to reproduce your issue, and It's very probable that it's the "find visible targets only" option that is causing that. Try to uncheck it in the AttackState (Anyway this option doesn't make much sense for a melee attack it's more thought for ranged attacks)
     
  14. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi @dpy , I've noticed that version 1.14 was added recently but for some reason when I try to download it the import screen is showing that I have already imported the latest version. Yet I cannot seem to find these 2 features:
    - Added an AI flying example, the "12_state_fly scene", it uses a regular patrol state but with a "FlightNavigator" script
    - Added a new group moving example scene "FormationMovingAndAttacking" where AIs can be sent in group to attack buildings
    Any chance that these features were not added yet?

    Edit:

    I have checked this again several times and I noticed that on the asset store page the above features are clearly listed in the package contents section, but for some reason even if I delete the entire folder, when I go to import the assets for the above two features are not in the import window.

    I'm using v5.5.1f could that be causing the issue?
     
    Last edited: Mar 24, 2017
  15. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Sorry @Hamesh81 for the late reply,
    yes it's due to the version, the package was uploaded with v5.5.2f
    If you update Unity you'll get the 1.14 version of AIBehavior
     
    Hamesh81 likes this.
  16. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi again @dpy , I was planning to update to Unity 5.6 but then I realized that there are a number of new navmesh features in that version. Will this affect AI Behaviors or break any of the existing functionality? I will probably hold off updating if that is the case, although the new navmesh tools look very promising and it would be great to use them with AI Behaviors.
     
  17. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hi @Hamesh81,
    it should work fine in 5.6, I tested it and I didn't got any problem :)
     
  18. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ok great I will update and try it out.
     
  19. clamchoda

    clamchoda

    Joined:
    Jan 21, 2017
    Posts:
    11
    1. Is there a way to get the 1.4 fixes into versions of unity before 5.6?
    I have an issue I have been trying to get fixed since the day I bought AI Behaviors. (I've tried with and without "find visible targets only).

    Ranged AI shoots multiple projectiles; Extra attacks only seem to happen when Attack Point Animation is anything but 1. Therefore, you can never synch up your attacks visually because it has to remain at 1.

    I'm trying to setup what I think is a pretty basic AI scenario. Perhaps I'm just way off base and need some direction.

    End Goal:
    Ranged AI which can see up to 15 meters. AI can have multiple targets. (2 players)
    Start in an Idle state (Trigger LineofSight to Seek)
    Seeks Enemy when seen within 15 meters (Trigger Nested WithinDistance 10 and LineofSite to Attack)
    Attacks after seeking when within 10 meters and not behind and visual obstructions
    If target is behind visual obstruction or greater than 10 meters, return to Seek

    2. Should this scenario be possible with Ai Behaviors?

    it is easy to setup this scenario using nested line of sight and within distance triggers. What I can never solve, is the issue of the AI shooting multiple projectiles, and not being able to use Attack Point Animation time to synch up the projectile with the attack animation.

    I'm trying to reframe from upgrading to 5.6 because there are a few annoying issues with Steam VR integration atm.

    3. Are the 1.14 fixes is directed at fixing the above scenario? I would probably have to consider the upgrade. Please let me know the best route...
     
  20. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hello @clamchoda
    This scenario is perfectly possible with AI Behaviors, and your settings seem to be right, I think this issue is fixed in the current version, but I understand your reasons to dont upgrading Unity, as I told you through private message just send me your email adress and I will send you the updated files you need to see if that solves the problem ;)
     
    clamchoda likes this.
  21. HashbangGames

    HashbangGames

    Joined:
    May 7, 2011
    Posts:
    40
    So I think I found a bug with the Animation Attack.

    In MecanimAttackState.cs you have it looking at the fullPathHash variable on line 44. That doesn't match what the hash is from Animator.StringToHash(animationStates[0].name) and it causes the block to exit.

    I changed this to the following:
    Code (CSharp):
    1.                 AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(mecanimLayerIndex);
    2.                 int hash = Animator.StringToHash(animationStates[0].name);
    3.  
    4.                 if ( hash == stateInfo.shortNameHash )
    5.                 {
    And it fixed it, however I'm not sure if that is the right fix, or if I have something wrong in my animation setup.

    Would like to know more. Is this a bug, or did I do something wrong?
     
  22. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    I think you're probably right. Thanks for pointing that out. Is this in Unity 5.6?
     
  23. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Okay, I took a look and it depends on whether you're using the full path in your Animation States or the short ones. By default, it expects the full name hash. I'm going to change this to allow for either of them.

    Examples:
    Full name hash - "Base Layer.Attack"
    Short name hash - "Attack"
     
  24. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Hello. Long time no see. I'm back grabbed the latest update to AI Behaviors.
    I have some questions
    1)Is there a way for the enemies to do stuff at random time? The old videos tutorials show him just attacking at the same rate always. But that's predictable

    2)How does the enemy know he is hurt? The videos show bullets and using a collider in the enemy. But what if the player attacks with a close range weapon or with FPS arms? And does his health decrease automatically when hit?

    ANd also how would the player know when he is being attacked and know which type of animation the enemy is performing(kick, punch or shoot bullets etc)?
     
  25. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hello,

    You could use a TimerTrigger and put a value into the "Plus Or Minus" field to give it some randomness. For instance, if you put the duration to 60 seconds and the plus or minus to 30 seconds it would have a random time between 30 to 90 seconds. Also, you can change the "Timer Reset Mode" to "When Triggered" if you want it to keep counting time even when it isn't in the state with this trigger. It will only be triggered when it is in the state it belongs to, however. So, even if the 30 to 90 seconds has passed, if the AI is in a different state it will not trigger until the AI switches to the state that this trigger belongs to. You can also use it as a global trigger in which case it will always consider it.

    You can have whatever weapon you are implementing call the AIBehaviors. GotHit(float damage) function.

    The attack state passes the AttackData struct, which contains the AttackState being used. Currently each attack state requires only a single animation. We have talked about how to implement using multiple animations per attack state. When that happens it likely should not break the current setup.

    Let me know if this answers your questions or not. Thanks! :)
     
  26. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Yes that answered my questions. The tricky part for me will be the scripting. i will be sure to ask when I come to do my attacks and stuff. thanks
     
  27. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Awesome, sounds great!
     
  28. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    I have the most basic of questions. I don't understand how to set up my character . The new manual says
    1)create an empty GameObject and add your character/avatar to it.
    That i did ended up with
    GameObject with my enemy as a child.

    2)On this GameObject add the "AIBehaviors" script and put the "NavMeshAgent"
    So i went to the empty gameObject and Add Component/and searched for the AIBehaviors script added it. Did the same for the NavmeshAgent script

    3)You should also add to this GameObject the "CharacterAnimator" or "MecanimAnimation" script, depending if you use Legacy or Mecanim animations.

    I Added the mecanimAnimation script


    *******So the result upon setting the initial state to Idle*****
    =It's not working. I can't add and pick mecanim state animations like in a prior version where i would type them as
    "BaseLayer.Name" in the AI Animations States section. That doesn't work. the only animation played is the default in the mecanim animation controller.
    =I notice there is no FOllow state anymore. Why did it get scrapped? What to do for our enemies to follow the player?

    I will keep trying to set up my AI Behaviors.
     
  29. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Hi I'm back. Instead of following those instructions I just selected my enemy character and went to the Tools menu/AI Behaviors/ and selected Mecanim Setup and it seemed to add most of what i needed. I just needed to add a Navmesh Agent. But still no matter what mecanim animation i choose, it only plays the default mecanim animation(the one connected to the entry and in orange color). Mmmmmm. What's going on i wonder.

    Yeah and i'm also still wondering why there is no FOllow state anymore, if you could answer that please

    PS I just noticed inside the Editor in the project window, in the Documentation folder of AIBehavior the Readme file says Version 1.13 at the top. Maybe i have version 1.13 and not Version 1.16 which is the one i'm supposed to have.mmmmm, how do i get the latest version.....I kind of remember i had this problem before.

    PS UPDATE: I now downloaded Unity 5.6 and so now i got Version 1.16. But i still don't see a Follow State anymore. Can you tell me why it was removed and what can we use instead?
    Here's a picture. You see in my Idle state AI Behavior i selected Base Layer.Idle2 to be the animation to play but if you look at the animator Idle1 is playing
     

    Attached Files:

    Last edited: Jul 3, 2017
  30. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    I'm back with good news. Now my Mecanim system is working. It plays the animation i select with AIBehaviors. The problem was i wasn't checking the Cross Fade In and Cross Fade out checkboxes. But when i did it worked.
    So are we always supposed to check those boxes?
     
  31. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Hi i don't know if this is part of AI behaviors or not but when my character I drag him to the scene he is planted on the ground yet when I push play and he performs mecanim animations he hovers a few inches off the ground. I tried going to the animation import settings and messing around but nothing helped.

    The only thing that helped kind of is when i bake a Navmesh also bake a Heightmesh. Is this correct to do or am i doing something wrong.
    Why does my character float?

    Do i need to put a Rigidbody on the character? It does look more planted with the Heightmesh though
     
    Last edited: Jul 4, 2017
  32. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Hello i'm back again with another question. My player is 14 distance away and i set the enemy trigger within Distance of 1 or 2 to begin seek state. But it begins seek state immediately even if i'm 14 or 17 distance away. Is this a bug or am i doing something wrong?

    UPDATE JULY 6 1:47am: Hi I'm back with good news but possibly found a bug too. So like i said this wasn't working but when i changed the trigger from Check State DEFAULT to Check State ALL it started working as it should. Again ,in case my above description didn't make sense , I have a trigger on my idle state to go from idle to seek when the player is say 3 distance within using the WithinDistance trigger. I was struggling to make it work correctly because the enemy would start Seek automatically upon Play . So today i changed Check State Default to Check state ALL and it worked. Is this a bug? or is it the way we should use it?

    UPDATE 2: I'm trying the beyond distance trigger and it's supposed to change speed and animations Beyond distance of 6, but it doesn't. Mmmmm i'll keep testing

    UPDATE 3: Oh fixed update 2. It was because i didn't specify a Seek target

    UPDATE 4: POssible bug between a state containing Timer Trigger and a created seek state(in my case i called it SeekRun to differeintiate from a Seek with walking anim). I'm noticing when i change the movement speed in my SeekRun , it changes my TimerTrigger in the Seek to whatever i put as the movement speed in my created SeekRun state. And also if i change the time in the Seek state which has the TimeTrigger, it changes the movement speed in my SeekRun to what i set the TimeTrigger in Seek to be. AND***** INterstingly if you change the Movement speed in my SeekRun using the mouse and left mouse button(instead of typing in values), then this problem doesn't happen. But it's annoying to enter movement speed or Time (seconds) using the mouse cause it's hard to get to the exact value you want.

    UPDATE 5: In Seek state, the Movement Speed doesn't seem to do anything. i set it less than 1 and it remains the same. am I doing something wrong?
     
    Last edited: Jul 6, 2017
  33. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Mmm i wonder what happpened. Is everyone on vacation?
     
  34. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Actually, yes, haha! Sorry About that :)

    For the follow state, that has been removed since you can replicate it's behavior using other states and triggers.

    If it's going directly to the seek state and all that's being checked for is outside of the within distance threshold and there are no other triggers, then check to see if the initial state is set to Seek. Also check to make sure your enemy isn't tagged with "Player" or whatever the tags are set to that are on the AI.

    So when you change the time on the timer it changes the movement speed on the state? That's very strange. Can you make a project with a scene that does this and send it to me or give steps to reproduce the issue?

    Which animation system are you using? If you're using Mecanim these values are more used for transitions than for actual speed. They can still be used for speed, but since Mecanim drives the movement of the character applying speed would make animations look like they are slow motion.

    Let me know if I missed anything or if you have any additional questions.

    Thanks!
     
  35. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Thanks for your replies. They made sense. One thing you didn't answer is for the problemwhere the enemy was began "seeking"(following) even if the player was 14 or 17 distance away
    UPDATE JULY 6 1:47am: Hi I'm back with good news but possibly found a bug too. So like i said this wasn't working but when i changed the trigger from Check State DEFAULT to Check State ALL it started working as it should. ​
    Why did i have to change Check State from Default to ALL for it to work? Also when i use Beyond state i have had to put Check State to ANY. I'm sorry it's confusing, but in sum, how do i know what to Change the Check State to?
    I've had to change it in 2 situations for it to work.

    **************************
    You SAID: So when you change the time on the timer it changes the movement speed on the state? That's very strange. Can you make a project with a scene that does this and send it to me or give steps to reproduce the issue?

    Yeah this problem is weird and strange. Well the first times i tried it , when i changed the time on the timer, it would change the movement speed on a different state. But now it's doing another thing. Say the Seek state has a timer trigger and another seek state i make called "SeekRun" Has another timer trigger, If in any of those states i change the time in the timer trigger and leave the cursor without pressing Return, it makes the other state have the same value in the timer Trigger.

    Here's another example. If on my seekstate i set the movement speed to 7 without pressing return, then i go to my seekstateRUn state and my GoTORandomState Trigger changes it's Number of possible states to 7 too.

    I'm guessing this problem is related to the fact i'm using two Seek States. Maybe ? :)
    *************************************************************************************
    And i have some questions:

    1.*HOW DO I DO ATTACK WITH BULLETS(Ranged attrack) OR SeekRUn and stop when he gets to the player and then do fighting hand to hand? In other words how do i set up a Do this or this at random probability.
    Well i tried the GoToRandomState trigger but i put SeekRun 0.8, Attack 0.2 but it keeps doing attack(bullets) and never does the SeekRun

    2. *How do I stop enemy when he gets close enough to the Player instead of circling around the Player?

    3. And if i could have an example of how to make the Player Make Enemy get Hit by bullets and take damage?
    And an example of how the player takes damage?
    I have to do all this by code right? I have no idea how.
     
  36. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Do you have more than one object with a player tag on it? "Any" mode is if any object is within distance and "All" requires all objects to be within the distance. So, if you have an object with a "Player" tag on your AI or some other object near it with the "Player" tag then it would automatically trigger it to be true. If you then changed it to "All" it would require all objects in the scene with the "Player" tag to be within the distance.

    As a side note:
    WithinDistanceTrigger's default is Any and BeyondDistanceTrigger's default mode is "All"


    Two seek states shouldn't cause this problem. It sounds more like a Unity inspector bug. I'll keep my eye out for it.

    That's strange, I'll have to take a look and see if there's a bug.

    I'm guessing the AI is colliding with the player and therefore circling the player because it never reaches it's destination. If you don't need to trigger anything additional in your AI you can set a stopping distance on the NavMeshAgent.

    So, I won't go into a lot of detail about how to specifically do these things, but will give you the core idea. There are several systems out there, like UFPS, that are designed specifically for how weapons work and they integrate pretty easily with our system.

    So, for a bullet, you'll want to use a raycast out of the main player's camera if you have an FPS game, or wherever your player is respectively to your game type. You'll need to fill in the variables yourself. Here is some sample code, but if you aren't good at scripting and want something more robust without learning how to write code, you'll definitely want to pick something up like UFPS. Here's a little code snippet anyway to get you started.

    Code (csharp):
    1. RaycastHit hit;
    2. if ( Physics.Raycast(startingPoint, cameraDirection, out hit, maxShotDistance, ) )
    3. {
    4.     AIBehavior.AIBehaviors ai = hit.transform.GetComponent<AIBehavior.AIBehaviors>();
    5.  
    6.     if ( ai != null )
    7.     {
    8.         ai.GotHit(damageAmount);
    9.     }
    10. }
    For how the player takes damage can be found in the 08_state_ranged_attack scene. There aren't any visual indicators of being hit, but we do print text to the console for the Player's current health. Mostly take a look at the ExampleAttackComponent and the ExampleProjectile script. You'll want to probably write new scripts to customize how your game works.
     
  37. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Thanks for the snippet. WHere would i drag this script to? And any tips on what startingPoint, cameraDirection and maxShotDistance should be set to?
    My game is just like an FPS type. Thank you for the mention of UFPS too but that's too expensive for me now.

    You gave me a snippet on bullets, how about hand to hand fighting? Would i need some type of colliders on the hands of player and enemies?
     
  38. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Hi i'm back. I"m working on the attack ranged state and have it set with a trigger of 10 Duration and Plus or minus 5.
    The enemy just keeps shooting forever and following me. However i can also trick him and quickly go behind him then he doesn't know where i'm at anymore and he keeps walking and shooting going to the opposite direction of where i'm at. Then runs into walls and keeps walking without able to pass.

    1)So my question is Why the Timer Trigger keeps triggering more time than it should. ? And why does my enemy not aware where i am if i just quickly go behind him?

    2)And i'm still unable to perform the Seek state from a RandomTrigger with 2 possiblities , even if they're both at .5
    I have Seek and Attack and it always performs atttack only.
     
  39. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    hi @greatUnityGamer ,

    I see you had a lot of questions...
    I sugest you to look closely to the example scenes: "AIBehavior/Scenes/Video_Examples/States"
    There are examples for almost all trigers and states, if you look the settings there you can have an idea about how it works and play with the settings to make what you want.
    You can find there also an example scene (10_state_got_hit) of player shooting at an AI and scripts that make the damage, etc. The "shooter" script is on the first_person_controler and the "ExampleGotHitComponent" is on the avatar_complete.

    Your issue with the random trigger, if your set up is right (having 0.5 as probability on each state) could be that your AI goes to the SeekState but has no target or cant reach it and goes back to Idle (take a look to the "NoSeekTargetTransition" and "NoMovementTransition" there).
     
  40. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    Do I have to use NavMesh for this asset?

    I need simple wander and flee behavior, but levels are created at runtime and have no NavMesh. Please help.
     
  41. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    Hi HakJak, you do need a NavMesh for AIs to walk on them, but there are options in case you can't have a previous baked mesh in your scene (as in your case).
    One option could be using A* (there are some example scripts in this asset).
    Another optino that you can try out is to use "Unity Runtime NavMesh Generation" (for Unity 2017), I havent tested this yet as its quite new, but there are some tutorials in Youtube:
     
    HakJak likes this.
  42. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    Thank you!
     
    dpy likes this.
  43. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    @HakJak
    We just uploaded a new version of AI Behavior and included an example of this Runtime NavMesh Generation used with an AI if you still need to get that done you can take a look on it. (AIBehavior/Scenes/Scene_Examples/RealTimeNavMesh/RunTimeNavMesh)
     
    HakJak likes this.
  44. dpy

    dpy

    Joined:
    Nov 14, 2016
    Posts:
    22
    We uploaded a new version of AIBhavior (1.17), here are the release notes:

    =====================================================
    Version 1.17
    =====================================================


    Features:
    ------------
    - Added user variables to the General AI Properties in the AIBehaviors script.
    - Added a "CheckVariableTrigger" that checks the specified variable values to change to another state
    - Added the posibility to change variable properties when entering a state.
    - Added an "RunTimeNavMesh" example scene showing how to generate a NavMesh at runtime working with AIs


    Changes:
    ------------
    - Updated documentation
     
    Hamesh81 and julianr like this.
  45. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Great additions here @dpy , thanks for these.

    I'm not sure how complex this would be to add, but I was thinking it would be useful to be able to choose an animation for when traversing a flat or vertical navmesh. Since the new navmesh tools allow for vertical navmesh movement it would be great to be able to walk/run on flat navmeshes but climb on vertical ones if that makes sense. Not sure if this would work best as a part of the offmeshlink state or as a new separate state?
     
    dpy likes this.
  46. LoDx

    LoDx

    Joined:
    Feb 13, 2013
    Posts:
    67
    Hi @dpy @NathanWarden @profcwalker ,
    just bought it moments ago, as it looks promising.
    However, when I tried to do test build , it keeps throwing errors :-
    aibehave-apkbuilderror1.jpg

    To reproduce :-
    1. Download & Import the assetpackage into new project.
    2. Try to build one of the demo scene that comes with the assetpackage.
    3. It just throws out the errors.

    Note :-
    * I did NOT change/edit anything, its a fresh import into new project.
    * the demo scene runs without error in editor/play mode, but throws error when trying to build.

    Thanks
    James
     
    Last edited: Oct 11, 2017
  47. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi James, sorry about the issue and thanks for pointing this out! I'm uploading a package with the fix as I write this. It will likely be up within an hour or two as version 1.17.1
     
    LoDx likes this.
  48. LoDx

    LoDx

    Joined:
    Feb 13, 2013
    Posts:
    67
    Hi @NathanWarden @dpy @profcwalker ,
    Thanks for the fix.

    Question :-
    - any plan for Photon (PUN) support ?

    I am stuck for 1week+, on trying to get aibehavior to work on Photon PUN , ( due to my lack of coding knowledge & skills,I am unable to overcome the serialization/sync for the ai , epspecially on the ai states to sync in multiplayer )

    Thanks
    James
     
  49. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi LoDx, I don't think we'll be integrating Photon anytime soon as I'm not personally familiar with it, so the integration wouldn't be up to the standard I'd want it to be. I'll talk with Daniel and see if he'd like to make a way to easily be able to serialize it and use it with any system. I can't make any promises on that though.
     
    LoDx likes this.
  50. gringan

    gringan

    Joined:
    Oct 27, 2016
    Posts:
    42
    Hello, i m making a VR Game. I made my own AI for Zombies but i m not happy with it. I use a simple walk, chase, attack With FOV and LOS and i have my animation controller already set. I only need melee, no range. I would like to know if it will be difficult to merge from my system to this one and keeping my animation controller .Also, if with this system, zombies are able to attack forming a circle around the target and so proc multiple attacks at same time. My system was problematic for that. Thanks.