Search Unity

AI Behaviors Made Easy! (Walker Boys)

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

  1. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    The patrol state is now working well. I took your suggestion and put the player in its own layer and unchecked it in visual obstructions menu. The problem is that I've got the distance trigger in the patrol state set such that when the player is within a distance of 20 units, the AI should switch to the follow state regardless of sight line. Instead what happens is that the AI begins to jitter, then scurries off sideways in the opposite direction to the player. The path gizmo shows a path that appears somewhat random but pointing away from the player. Once out of range , the AI returns to normal patrol behavior.

    However, the line-of-sight trigger works fine. If I position the player in front of the patrolling AI, it immediately follows. It's only the "within distance" trigger that seems to be causing trouble. It's weird.
     
  2. Intrawebs

    Intrawebs

    Joined:
    Mar 24, 2011
    Posts:
    45
    I poked around and finally figured it out. I've been creating a ton of custom triggers and some states so that your scripts can work with AI that are carrying more than one weapon to attack with as well as different firing modes per weapon. It's going well. But, I dont see any of the reload properties and attack distance properties actually being used in "AttackState", are they just stubs for future use? If so, It might actually be better to leave that up to weapon and or weapon inventory code, or, I can see how your individual attack states can each represent and be a weapon class themselves. The downside is I still need a broker to make decisions based on what weapon should be fired.
     
  3. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hello,

    I have a game object which has AIBehavior compoents like the following:

    $AIBehavior01.png

    As the 'States' gameobject which is child object of the gameobject which has AIBehavior component is shown on the inspector view, there are too may duplicated states and triggers. (See below)

    $AIBehavior02.png

    Why this is happened?


    Thank you.

    -Kim
     
  4. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    @tool55

    Hi Tool, I would probably have to take a look at the actual scene to debug your particular situation. If you feel safe doing so, you can email me your project at nathanwarden@icloud.com and I'll take a look as soon as I can.

    @Intrawebs

    Hi Intrawebs, there definitely might be a few obsolete/depricated fields in the code, I'll take a look and update the code appropriately.

    @kimsama

    This is a bug, the cause is if you add a trigger to a state, then remove that state, it doesn't remove its' triggers.

    To answer the ScriptableObject question from your email, this is actually how I had began implementing the system until I realised that when you assign your AI character from being a regular scene instance to a prefab all of the scriptable objects are lost. I would much rather use ScriptableObjects or Serializable classes for this system, but it looks like there are huge barriers to both. So, if you happen to know a clean way around this I would be more than happy to implement it that way instead.

    Thanks for the bug report too :)
     
  5. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi,
    Is there some way to autopopulate the Animation States, similar to the FBX Importer script?
    It's a little time consuming to manually set up if there are many animations, and would be a lot better workflow if it would just parse the character and populate the states automatically.

    ty!
     
  6. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    I hope it to be fixed soon. :)

    About the story of ScriptableObject, it should be serialized to a separated .asset file not to lose its values. Just deriving ScriptableObject instead of MonoBehaviour is not enough to be persistent as I know. But I'm not sure exactly what you've mentioned 'the huge barrieres' means.

    And thank you for the answer.


    Most of the implementation for AIBehavior package is cool, especially using Reflection for inspector view is impressive.

    It was easy to set AI up for enemies and even integrated with already existing Sage Animation Controller which we use for character's animation system.


    - Kim
     
  7. Intrawebs

    Intrawebs

    Joined:
    Mar 24, 2011
    Posts:
    45
    I take it that turning a gameobject that has the AI scripts on it along with animations and making it a prefab is not supported? When I make it a prefab I get the following.

     
  8. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    I think this had come up with us when we were developing it initially. We think it's a good idea and we eventually want to do it, it's not too high on the list though, so I can't promise anything.

    Thanks Sonic.

    Thanks Kim for the compliments. Do you happen to know of a plugin that implements scene assets this way? I really would like to find a cleaner solution and it would be nice to have some reference.

    I will try and get that bug fixed today :)

    Hi Intrawebs, I've never seen that issue before, but will take a look. Which version of Unity are you using, and is this a bare bones AI rig, or is there anything special in it?

    Thanks guys,
    Nathan
     
  9. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    I'd like to pause game play by setting Time.timeScale=0.0. But it seems to break AIBehaviors (the characters dissappear when the timeScale is set back to 1.0. Any ideas on why this might be and how to fix it?
     
  10. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    One more bug of AIBehavior.

    If the sight FOV get the angle over 180 degree, it is not correctly displayed.
     
  11. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hello,

    The following list is cool references what I know:

    1) You should first read it if you didn't see the page 'Serialization Best Practices'.

    http://forum.unity3d.com/threads/155352-Serialization-Best-Practices-Megapost?p=1064609#post1064609


    2) 'Unity Pro Tip: Use Custom Made Assets As Configuration Files' pages also shows how to ues custom asset file as configuration file with specific example.

    http://www.jacobpennock.com/Blog/?p=670


    3) The source code of Twisted Oak Studio's AssetBundleHelper also shows an usage of storing configuration to an .asset file.

    http://twistedoakgames.com/blog/?p=74


    4) Fury Framework uses seperated asset files to store stat of each unit.

    http://forum.unity3d.com/threads/116711-RELEASED-Fury-Framework-RPG-RTS-Creator

    http://video.unity3d.com/video/6944412/unite-2012-asset-bundles


    5) Sage Animation Controller stores all its animation graph to an .asset file and uses it at run time for an animation of a gameobject.

    http://forum.unity3d.com/threads/12...Graph-Editor-Control-your-Animations-Visually!


    There are many other plugins or packages which serialize its data to .asset files whenever its data is changed the reflect it on an editor window or inspector view.

    One of pros when AIBehavior uses .asset file for serializing its data is that multiple character's AI set up can be done with just duplicating and assign same .asset file to each gameobjects if all those has same AI.

    Hope this help on the case.


    Cheers,


    -Kim
     
  12. matis1989

    matis1989

    Joined:
    Mar 23, 2011
    Posts:
    162
    Hi NathanWarden,
    me again:) First of all thank you for your answer now it is work. Unfortunately I have one more problem. Iam trying to set AI like you on your 01 example behavior but Follow state give me hard time. When is player within distance AI switch to follow state and it should follow/chase player but this dont gone happened because AI create target gameObject somewhere else than to player position. Iam pretty sure I set everything like as video show. This is happened even when I use just follow state. Is here something what I need to set up expect player tag?
    Thank you for your answer.
     
  13. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I stopped using follow for this very reason and set up a seek action to seek the player instead and no more wandering AIs.
     
  14. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Thanks Kim,

    We may eventually use our own system like this since I believe we can't use asset files without forcing our userbase to use Unity Pro (correct me if I'm wrong). However that wouldn't keep us from having text files in the project much in the same way as Unity's meta files work.

    Thanks again,
    Nathan :)
     
  15. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hey Matis,

    The key thing for the follow state is that the thing you want the AI to follow must have a tag that is specified in the AI's general settings (the default layer is "Player"). If the thing you want the AI to follow has a collider on it, the collider must also be in a layer that is unchecked in the visual obstruction layers.

    Hope this helps,
    Nathan
     
  16. matis1989

    matis1989

    Joined:
    Mar 23, 2011
    Posts:
    162
    Thanks a lot:)
     
  17. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Making .asset file with CustomAssetUtility is not pro only feature. It is just a serializing.

    What pro only featrue is assest bundle.


    -Kim
     
    Last edited: Nov 30, 2012
  18. wiNtz

    wiNtz

    Joined:
    Oct 24, 2012
    Posts:
    15
    Hello. Can you tell me what I getting this error while I trying to create AI on my own map ?




    On example maps my enemy works fine, without errors. I adding same enemy no my map (with saved configurations from example maps) and this error shows up.
     
  19. wiNtz

    wiNtz

    Joined:
    Oct 24, 2012
    Posts:
    15
    Sorry for double posts but if someone will have same problem he need to bake his terrain.

    1. Click on terrain.
    2. Navigation
    3. Bake
    4. Click on "Bake" button.

    Now everything works !
     
  20. matis1989

    matis1989

    Joined:
    Mar 23, 2011
    Posts:
    162
    Is possible change tag in seek state in runtime? I have script that change tag for "Seek Items with Tag" in game. In editor I can see that tag is changed on AIBehaviors script and also on "States" gameobject in hierarchy. Problem is my AI still seek for tag that was set before game was start - "Target" gameobject is still on object with first tag.
    Hope you understand my question and thank you for your answer.
     
  21. NathanWarden

    NathanWarden

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

    That's a great question. After you change the tag on the item(s), you need to call CheckForPlayers on the AI because I'm caching the tagged objects for performance reasons.
     
  22. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Sorry for the wrong answer.

    Yes, you are. Serializing to asset is Pro only feature.


    -Kim
     
  23. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Kim, no biggie, haha. If we do end up implementing this feature, we'll more than likely just create our own text based data files which will pretty much do the same thing that we'd need an asset file to do.

    Thanks for taking a look at some options that might help.
     
  24. wmgcata

    wmgcata

    Joined:
    Jul 20, 2012
    Posts:
    169
    I might get this asset soon! Even though, i'm just wondering if it's possible to add a bit of recoil or possibility to miss the character an enemy is shooting it through the range attack function. If you could answer this, thanks.

    Tim
     
  25. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    Hi,
    I'm currently working my way through mecanim and getting to grips with the new animation and state control system.
    Will AI Behaviors support hooking into this or will you have to use the legacy system?

    ty!
     
  26. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Tim, we don't actually handle any individual weapons since that would be a project in and of itself. Rather, we tell you when it should fire and you code the actual weapon behavior yourself. If you need the state itself to do something different than what it already does, you can duplicate the code file and rename it and the class and then modify it from there. Our system will automatically detect the new state that you made. That goes for triggers as well.

    Hi sonicviz, I may try and tackle this soon. In the meantime you can call out to Mecanim yourself by replacing the AIBehaviorsCharacterAnimator script with another script. It just needs a method named "public void OnAnimationState(AIBehaviorsAnimationState animationState)". You can then pass mecanim the animationState.name. I haven't really played much with Mecanim, but as long as your animations are setup correctly in Mecanim and in AI Behaviors it should do the trick. Again, I'm going to play with this a bit so I can be more confident in my answer.
     
  27. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    I'm using AI Behaviors with Granberg's Pro A* Pathfinding. It works great with one AI and the PathResponder script from your video tutorial. But when I add a second AI, they interact. For example, I have a trigger in the patrol state that switches to "follow" when the Player gets within a certain distance of the AI. But when the player moves close to the first AI, the second AI switches to follow, too, regardless of distance. I've assigned separate patrol points and separate empty target objects to the PathResponder script attached to each AI, and to the AI Path script, so that isn't the problem. Is there a way to have multiple AI characters in the scene and have them all behave independently? Or am I doing something wrong.

    Thanks for the help.
     
  28. NathanWarden

    NathanWarden

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

    That sounds like a really weird issue, can you by chance send your project to me?

    Thanks,
    Nathan
     
  29. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hey,

    Just upgraded AIBehavior 1.3.6.

    Thank you for the fixing of removing triggers when it was deleted. (checked via WinDiff but did not tried the changes yet on my side)

    After upgrading, opened AI vs AI.unity scene and ran then I got the following error:

    As I saw the changes of the code, you replaced Destroy to DestroyImmediate in IdleState.cs and which seems to make the above error.


    Best regards,

    -Kim
     
  30. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi Kim, thanks for spotting this and letting us know, I fixed this as of a few hours ago and will be in the next release. :)
     
  31. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hey,

    1)
    I cannot change an animation's wrapmode to 'Once'.

    It is always shown as 'Clamp'

    Changing to 'Loop' is available but cannot change to 'Once'.

    $unity_aibehavior01.png

    2)
    Second question.

    I made a new CommonEnemyAttackState class which is derived from AttackState.

    On edit mode, specifying to CommonEnemyAttackState is ok, but it quickly changes to AttackState when I turn on play mode.

    $untiy_aibehavior02.png

    3)
    I also got the following error when it runs:

    I created AIBehaviorsEnemyAnimator class and it has OnAnimationState method which has AIBehaviorsAnimationState for its parameter.

    Code (csharp):
    1.  
    2. public class AIBehaviorsEnemyAnimator : MonoBehaviour
    3. {
    4.  
    5.     Animation anim = null;
    6.     bool hasAnimationComponent = false;
    7.  
    8.  
    9.     void Awake()
    10.     {
    11.         anim = GetComponentInChildren<Animation>();
    12.  
    13.         hasAnimationComponent = anim != null;
    14.  
    15.         if ( !hasAnimationComponent )
    16.         {
    17.             Debug.LogWarning("No animation component found for the '" + gameObject.name + "' object or child objects");
    18.         }
    19.     }
    20.  
    21.  
    22.     public void OnAnimationState(AIBehaviorsAnimationState animState)
    23.     {
    24.         if ( hasAnimationComponent  animState != null )
    25.         {
    26.             string stateName = animState.name;
    27.  
    28.             if ( anim[stateName] != null )
    29.             {
    30.                 anim[stateName].wrapMode = animState.animationWrapMode;
    31.                 anim[stateName].speed = animState.speed;
    32.                 anim.CrossFade(stateName);
    33.             }
    34.             else
    35.                 Debug.LogWarning("The animation state \"" + stateName + "\" couldn't be found.");
    36.         }
    37.     }
    38. }
    39.  
    And the animation component is set as the following:

    $untiy_aibehavior03.png

    4)
    On last, I cannot change any values of AIBehavior component shown on the inspector view by typing.

    Changing value with mouse by moving it left or right side is ok, but cannot directly type within any FloatField or IntField of GUILayout.

    $unity_aibehavior04.png

    I use Unity 4.0.0f7 with AIBehavior 1.3.6 which is available on AssetStore. (As I guess 1.3.6 is the latest one, right?)


    Cheers,

    -Kim


    [Edit]
    Changing values of the prefab by typing directly in the project view is fine but changing the value of the prefab which is on the hierarchy view is impossible.
     
    Last edited: Dec 13, 2012
  32. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    1), 2)
    I rebuilt AIBehaviors from the scratch and I sure I got same result.

    And there is the bug, still some deleted states and triggers are remained on State game object.

    3)
    Forgot to specify attack animation for "Attack animation: " beflow Animation Setting section. That solved the problem.

    4)
    It might be a Unity bug. I restarted Unity and now, that is gone. (but I'm not sure, why only AIBehaviors component's values are disabled)


    Cheers,

    -Kim
     
  33. NathanWarden

    NathanWarden

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

    1) This is a actually Unity issue (but not really even an issue at the same time). The problem is that the WrapMode.Once and WrapMode.Clamp are the same value. So, even though I'm using the EditorGUILayout.PropertyField method, Unity itself cannot tell whether you wanted Once or Clamp. And it doesn't really matter anyway as they'll both cause your animations to do the same thing.

    2) Thanks for letting me know, do you happen to have steps reproduce this?

    4) I've noticed this with Unity's editor input fields a number of times. Sometimes they only allow you to type X number of characters for some reason and I agree, restarting does tend to solve the problem.

    Thanks Kim,
    Nathan
     
  34. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Thank you for the answers.

    Let me show you my own simple CommonEnemyAttackState:

    Code (csharp):
    1.  
    2. public class CommonEnemyAttackState : AttackState
    3. {
    4.     float reload = 0.0f;
    5.    
    6.         protected override void Init(AIBehaviors fsm)
    7.     {      
    8.         fsm.MoveAgent(fsm.transform, 0.0f, rotationSpeed);     
    9.     }
    10.    
    11.     protected override void StateEnded(AIBehaviors fsm)
    12.     {
    13.         reload = 0.0f;
    14.     }
    15.    
    16.     protected override bool Reason(AIBehaviors fsm)
    17.     {
    18.         return true;
    19.     }
    20.    
    21.     protected override void Action(AIBehaviors fsm)
    22.     {
    23.                 Debug.Log ("############## CommonEnemyAttackState ");
    24.  
    25.                 //
    26.                 // DO MY OWN ENEMY ATTACK CODE HERE
    27.                 //
    28.     }
    29.    
    30. #if UNITY_EDITOR
    31.     public override void OnStateInspectorEnabled(SerializedObject m_ParentObject)
    32.     {
    33.         UpgradeLegacyDerivedState(m_ParentObject);
    34.     }
    35. #endif 
    36. }
    37.  
    I selected this class on the inspector view of AIBehaviors component.

    The problem is that CommonEnemyAttackState.Action() is never called but AttackState.Action() is called on the runtime.

    You may easily reproduce this with the above code.

    Best,

    -Kim

    [EDIT]

    I use Unity 4.0.0f7 withe the latest version of AIBehavior.
     
    Last edited: Dec 18, 2012
  35. NathanWarden

    NathanWarden

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

    Quick answer: The method "UpgradeLegacyDerivedState" you can delete as it should only be in two legacy scripts (Melee and Ranged Attack).

    The code that's causing the problem is this method call. This code is in there because we moved Ranged Attack and Melee Attack to both simply be the base Attack state. Since we're going to eventually remove those two scripts out of the system completely, this is how I converted everybodys' code over (who was on the legacy 1.0 version) to just use attack state.

    Hope this helps,
    Nathan
     
  36. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    Hi,

    I'm having an issue with the follow state. I have it set to switch from "patrol" to "follow" when A) the player is in line of sight or B) the player is within 30 units distance.

    Line of sight works great every time. And within distance works, too, at least at first. The problem is that if the AI is in the follow state and I then run my player behind the AI, the AI freezes. It doesn't rotate toward the player. I can see that it's still in the follow state because the follow animation (a faster walk) is switched on, but the AI is locked in place and the fast walk animation continues. The only way to break this frozen state is to run the Player around the front of the AI so it's in line of sight again. Then the AI follows normally. The other way to break it is to move the player outside the "follow" distance. It then switches back to patrol. I'm using Granberg's Pro Pathfinding and a recast graph. (I tried it with a grid graph and the same thing happens). I have the player on its own layer and the AI on its own layer, both unchecked in visual obstructions. Just wonder if anyone else has had this issue.
     
  37. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Thank you. It was fixed now.

    By the way, changing a state does not remove a previous state.

    For example, after changing CommonEnemyAttackState, AttackState component is still remain on State game object which is automatically added under a game object when AIBehaviors added.



    -Kim
     
  38. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hello,

    I wrote a simple trigger extension which waits till the animation is done and changes AIBehaivors's state.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System;
    5.  
    6. #if UNITY_EDITOR
    7. using UnityEditor;
    8. #endif
    9.  
    10. ///
    11. /// WaitForAnimationTrigger class.
    12. ///
    13. /// It waits until the animation is done by the given ratio, and changes to the specified state.
    14. ///
    15. /// 2012. 12. @kimsama
    16. ///
    17. public class WaitForAnimationTrigger : BaseTrigger
    18. {
    19.     public float duration = 1.0f;
    20.    
    21.     private Animation animation = null;
    22.     private bool isStarted = false;
    23.    
    24.     ///
    25.     /// Awake
    26.     ///
    27.     void Awake()
    28.     {
    29.         animation = this.gameObject.GetComponent<Animation>();
    30.         if (animation == null)
    31.             animation = this.gameObject.transform.parent.GetComponent<Animation>();
    32.     }
    33.    
    34.     ///
    35.     ///
    36.     ///    
    37.     protected override void Init()
    38.     {
    39.         this.isStarted = false;
    40.     }
    41.  
    42.     ///
    43.     ///
    44.     ///
    45.     protected override bool Evaluate(AIBehaviors fsm)
    46.     {      
    47.         bool ret = false;
    48.        
    49.         if (this.isStarted == false)
    50.         {
    51.             this.isStarted = true;
    52.            
    53.             string name = "";
    54.             for(int i=0; i<fsm.currentState.animationStates.Length; i++)
    55.             {
    56.                 name = fsm.currentState.animationStates[i].name;
    57.                 if (animation.IsPlaying(name))
    58.                 {
    59.                     StartCoroutine(WaitForAnimation(name, this.duration, ()=>{
    60.                         fsm.ChangeActiveState(transitionState);
    61.                         ret = true;
    62.                     }));                    
    63.                     break;
    64.                 }
    65.             }
    66.         }
    67.        
    68.         return ret;
    69.     }
    70.    
    71.     ///
    72.     /// Wait for the animation is done till the given ratio.
    73.     /// The ratio has the value between [0, 1].
    74.     ///
    75.     public IEnumerator WaitForAnimation(string name, float ratio, Action onComplete)
    76.     {
    77.         var state = animation[name];
    78.         return WaitForAnimation(state, ratio, onComplete);
    79.     }
    80.    
    81.     ///
    82.     /// Wait for the animation is done till the given ratio.
    83.     /// The ratio has the value between [0, 1].
    84.     ///
    85.     public static IEnumerator WaitForAnimation(AnimationState state, float ratio, Action onComplete)
    86.     {
    87.         state.wrapMode = WrapMode.ClampForever;
    88.         state.enabled = true;
    89.         state.speed = state.speed == 0 ? 1 : state.speed;
    90.         var t = state.time;
    91.         while((t/state.length) + float.Epsilon < ratio)
    92.         {
    93.             t += Time.deltaTime * state.speed;
    94.             yield return null;
    95.         }
    96.        
    97.         if (onComplete != null)
    98.             onComplete();
    99.     }  
    100.  
    101. #if UNITY_EDITOR   
    102.     // Implement GUI editor script for specifying animation ratio.
    103.     public override void DrawInspectorProperties(SerializedObject sObject)
    104.     {
    105.         SerializedProperty prop;
    106.  
    107.         prop = sObject.FindProperty("duration");
    108.         if (prop.floatValue < 0.0f)
    109.             prop.floatValue = 0.0f;
    110.         if (prop.floatValue > 1.0f)
    111.             prop.floatValue = 1.0f;
    112.        
    113.         EditorGUILayout.PropertyField(prop);       
    114.     }
    115. #endif
    116.    
    117. }
    118.  
    You can also check it at the following gist:



    Thank you.

    -Kim
     
  39. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Sorry I've been away for the last week Tool. Thanks for letting us know. I'll have to see if I can reproduce this and give you the solution if I find it.
     
  40. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Awesome, thanks a bunch Kim for sharing that with everyone :)
     
  41. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    There is still a problem to remove a trigger when it is unchecked.

    Whenever trigger toggle button is unchecked, the following error message is shown on the console:

    So, to fix the problem, DestroyImmediate (theObject, true) should be called not DestroyImmediate((theObject).

    At the line 77 in AIBehaviorsTriggersGUI.cs, change the line as the following:
    Code (csharp):
    1.  
    2.     // causes the error
    3.     //Component.DestroyImmediate(currentTrigger);
    4.     Component.DestroyImmediate(currentTrigger, true);
    5.  
    It should fix the problem.

    - Kim
     
  42. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    I recently purchased Ai Behaviours so thought I'd drop in say Hi :)

    Which Nav A* system would you suggest to run with Ai Behaviours ?
    I am creating a 3D game for iPad iPhone.


    I have Unity4 Pro ( built in NavMesh ) but I also have Granberg's A* Pro which has NavMesh + Grid systems.

    I notice that Unity4 NavMesh allows for animated dynamic obstacles that agents avoid... but I'm not sure if this is will reduce FPS ?

    Currently I'm prototyping using Astar Pro since Walker Bros have acouple of great intro vids on how to apple Ai Behaviours to ASTAR.


    p.s Awesome job on creating Ai Behaviours.. love the interface integration, seamless with Unity4.
     
    Last edited: Jan 6, 2013
  43. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    Is it possible to have an agent circle its target before striking rather than simply run up and strike ? ( like a pack of wolves circling ) This would work well for non-violent games too such as a cute character circling before finally planting a kiss on another character's cheek. :p
     
    Last edited: Jan 6, 2013
  44. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    I am following the video lesson "Astar Pathing Implemented 2 " I have an agent patrolling and I have the target changing way points too.. works great .. but the problem starts after I add the final piece of code ( in Bold )


    So everything works great until I add that piece of code shown in BOLD.

    When the code is not commented out the target won't change way points.

    I added the sample AIFollow script to an agent as well to see if this was required... but I still get the errors.

    If I comment that code out then Agent#2 with the AIFollow script will move and begin to follow Agent #1.
    This is not what I require as I'm trying to go from Idle to Follow back to idle when out of range.
     
    Last edited: Jan 6, 2013
  45. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    Great to see such an amazing Product.. a very exciting time to be in the gaming arena.
     
    Last edited: Jan 7, 2013
  46. NathanWarden

    NathanWarden

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

    Sorry this is a little late, I've been away due to Christmas and have been pretty busy as well.

    Are the errors you're getting ones that show up in the console, or simply that it won't switch patrol points?

    If it's just that the patrol points aren't being switched, a common problem is that it doesn't ever come within distance of the patrol point due to going too fast per the minimum distance required. The solution for this is to change the "Distance Threshold" in the patrol state to something larger. The default of 1 may be a little too small in some situations.

    If it's an error that shows up in the console, can you paste the error in a reply and I'll take a look?

    To answer your questions from earlier:

    >> Which A* system should I use

    Personally, I prefer Unity's internal system mainly due to its' simplicity, your FPS can drop when using Obstacle avoidance, which you can turn off. As long as you don't have an unreasonable number of AI's in your scene, either one should do just fine. With iOS and Android, you'll probably run into GPU bottlenecks before you'll run into CPU bottlenecks from a pathfinding system. Maybe one of these days when I'm a little less busy I'll do some tests to see how many AI agents I can get into a barebones scene on my Nexus 7 before it drops under 30 fps.

    >> Is it possible to have an agent circle its target before striking rather than simply run up and strike?

    That sounds like a good state for us to add at some point as I've had to implement something like this for a recent client's project. I won't be able to get around to it for a little while though, so here's the link to the video on YouTube for creating your own states (which I think you had emailed us about).

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

    >> p.s Awesome job on creating Ai Behaviours.. love the interface integration, seamless with Unity4.

    Thanks a bunch Mick, this means a lot to us :)

    Nathan
     
  47. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    Ok I have tried running the game again yes you are right, the agent stops as soon as it hits the first navpoint.

    I have three agents running all stop after hitting their way points.

    her's the error I get

    NullReferenceException: Object reference not set to an instance of an object
    PatrolAuto.onMove (Vector3 targetPoint, Single targetSpeed, Single rotationSpeed) (at Assets/PatrolAuto.cs:22)



    After watching it run a few times, I notice the error occurs before they make contact with the nav point. the error occurs in the console almost as soon as I hit play but the agent kepps moving to the first target and then stops on it.
     
    Last edited: Jan 7, 2013
  48. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    I was going to add the LOG but its huge... if you need to see it I can always e-mail it.
     
    Last edited: Jan 7, 2013
  49. NathanWarden

    NathanWarden

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

    Looking at your code again, it looks like you never assign your "follower". Thus, when you try to modify it, it's null and throws a null reference exception. Adding:

    follower = GetComponent<AIFollow>();

    to the Awake method will likely fix your problem as long as there's the AIFollow component on the same GameObject as your AutoPatrol component.

    Hope this fixes your problem,
    Nathan
     
  50. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    Brilliant ! that was the culprit.... not to mention my lack of coding skills :(

    think its time I learn C#

    thx heaps :)