Search Unity

ICode (AI For Mecanim 2.0)

Discussion in 'Assets and Asset Store' started by DevionGames, Dec 18, 2013.

  1. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    It's not a big deal since I'm currently prototyping, so I'll stick with what I've got for now.

    I've easily got the asking price's value out of this just from time saved so far, so I'm not upset or anything., but how long are changes like this going to be happening for? I accept that it's in beta, but I'd have thought that meant it was in bug-searching territory rather than re-architecture territory.

    My other main feedback would be about improved documentation, both in the code and in the manual. A lot of stuff isn't documented, or has documentation that doesn't say anything useful. For example, the Animator CrossFade action's manual documentation doesn't mention what the "Equals" property does, and otherwise just says "Create a dynamic transition between the current state and the destination state" which is just a definition of what it's named after. The result is that I had to dive into the code to see what was up, and I haven't seen many (or any?) comments in there explaining the architecture. Thankfully the code is really nicely structured and easy to follow, so that hasn't been too bad. And I do accept that the system is in beta, so the docs are still a work in progress.
     
  2. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Well, i hope this is the last time for re-architecture, but if i find a better way of doing things, i try to implement that. The public fields are commented so far with new tooltips and there are also comments what the action/condition does. Most actions and condition do not have much code in them and the code itself is not much documented right now.

    Most actions are also only a few lines of code:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace StateMachine.Action{
    5.     [Info (category = "Application",    
    6.            description = "Loads the level by its name.",
    7.            url = "https://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html")]
    8.     [System.Serializable]
    9.     public class LoadLevel : StateAction {
    10.         [FieldInfo(tooltip="The name of the level to load.")]
    11.         public StringParameter level;
    12.        
    13.         public override void OnUpdate ()
    14.         {
    15.             Application.LoadLevel (level.Value);
    16.             Finish ();
    17.         }
    18.     }
    19. }
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace StateMachine.Action{
    5.     [Info (category = "CharacterController",    
    6.            description = "Moves the character with speed.",
    7.            url = "https://docs.unity3d.com/Documentation/ScriptReference/CharacterController.SimpleMove.html")]
    8.     [System.Serializable]
    9.     public class SimpleMove : StateAction {
    10.         [FieldInfo(canBeConstant=false, requiredField = false, nullLabel = "Owner", tooltip = "A game object that has a CharacterController")]
    11.         public ObjectParameter gameObject;
    12.         [FieldInfo(tooltip = "The direction to move towards.")]
    13.         public Vector3Parameter direction;
    14.         [FieldInfo(tooltip= "The direction is relative to the world or the Game Object.")]
    15.         public Space space = Space.World;
    16.        
    17.         [FieldInfo(tooltip = "The speed to move.")]
    18.         public FloatParameter speed;
    19.        
    20.         private CharacterController controller;
    21.        
    22.         public override void OnEnter ()
    23.         {
    24.             if (gameObject.Value == null) {
    25.                 gameObject.Value=stateMachine.owner;
    26.             }
    27.             controller = ((GameObject)gameObject.Value).GetComponent<CharacterController> ();
    28.         }
    29.        
    30.         public override void OnUpdate ()
    31.         {
    32.             if (controller == null) {
    33.                 Debug.LogWarning("Simple Move requires a CharacterController on the game object.");
    34.                 Finish();
    35.                 return;
    36.             }
    37.            
    38.             if (space == Space.Self) {
    39.                 controller.SimpleMove (controller.transform.TransformDirection (direction.Value) * speed.Value);
    40.             } else {
    41.                 controller.SimpleMove (direction.Value * speed.Value);
    42.             }
    43.         }
    44.     }
    45. }
    I still need to make some checks inside actions, for example checking if the StringParameter is not empty and if it does give a warning. The structure of the code is much more cleaner now.

    Here is also an example of a condition:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace StateMachine.Condition{
    5.     [Info (category = "Physics",    
    6.            description = "Returns true if there is any collider intersecting the line between start and end.",
    7.            url = "http://docs.unity3d.com/Documentation/ScriptReference/Physics.Linecast.html")]
    8.     [System.Serializable]
    9.     public class Linecast : StateCondition {
    10.         [FieldInfo(tooltip="Start position.")]
    11.         public Vector3Parameter start;
    12.         [FieldInfo(tooltip="End position.")]
    13.         public Vector3Parameter end;
    14.         [FieldInfo(tooltip="Layer masks can be used selectively filter game objects for example when casting rays.")]
    15.         public LayerMask layerMask;
    16.         [FieldInfo(tooltip="Does the result equals this condition.")]
    17.         public BoolParameter equals;
    18.  
    19.        
    20.         public override bool Validate ()
    21.         {  
    22.             return Physics.Linecast(start.Value,end.Value,layerMask) == equals.Value;
    23.         }
    24.     }
    25. }
     
    Last edited: May 12, 2014
  3. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Hello, like stated above there will be some changes again that will break your created "AI Controller" and i realy apologize for this. I have some more information on the update. The example scenes will move back to the project, because some people complained that they can not find them(I removed them just to save download size, if you do not need them).

    If you would like to test this already, please pm me your invoice number.

    You can read about it here.

    Video tutorials

    Overview:

    Random Walk:

    Meele Attack:

    Player Animation:

    Script Integration:
     
    Last edited: May 16, 2014
  4. Archania

    Archania

    Joined:
    Aug 27, 2010
    Posts:
    1,662
    Zerano
    I am not sure if it is my phone playing the videos or something is really wrong with your voice. Lol
    The player animation and script integration videos aren't playing. Just letting you know.

    Edit: well they play fine in youtube.
     
    Last edited: May 16, 2014
  5. Pirogun

    Pirogun

    Joined:
    Dec 1, 2012
    Posts:
    31
    Hello, I recently purchased your asset and I wanted to integrate it with Unity so I saw the video for melee damage and I followed the video through. The AI personality works as I want it to but there is one thing that doesn't seem to work and that is damage inflicted on the player.
    I used this script:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ForwardDamage : MonoBehaviour {
    5.  
    6.     public LayerMask mask;
    7.     public float maxDistance=2.2f;
    8.     public string methodName="Damage";
    9.  
    10.     private void SendDamage(float damage){
    11.         RaycastHit hit;
    12.         if(Physics.Raycast(transform.position, transform.forward, out hit, maxDistance, mask)){
    13.             hit.transform.SendMessage(methodName,damage,SendMessageOptions.DontRequireReceiver);
    14.         }
    15.     }
    16. }
    I have used my Player and the advanced player prefab from UFPS but to no avail.
    I also would like to know how to kill the zombie and give it health. Thank You!
     
  6. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Do you added an event to your animation-> Are you receiving the "SendDamage" method at all? Can you debug it using this:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ForwardDamage : MonoBehaviour {
    5.  
    6.     public LayerMask mask;
    7.     public float maxDistance=2.2f;
    8.     public string methodName="Damage";
    9.  
    10.     private void SendDamage(float damage){
    11.                 Debug.Log("Message received.");
    12.         RaycastHit hit;
    13.         if(Physics.Raycast(transform.position, transform.forward, out hit, maxDistance, mask)){
    14.                         Debug.Log("Hit: "+hit.transform.name);
    15.             hit.transform.SendMessage(methodName,damage,SendMessageOptions.DontRequireReceiver);
    16.         }
    17.     }
    18. }
    Could you let me know if both logs are printed into the console?
     
  7. Pirogun

    Pirogun

    Joined:
    Dec 1, 2012
    Posts:
    31
    I have the event in my animation and I have received both messages in the console.
     
  8. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Well what does the second message print? UFPS has a collider that is added on Start as child, do you disabled this feature and added a collider to the root transform of your player?
     
  9. Pirogun

    Pirogun

    Joined:
    Dec 1, 2012
    Posts:
    31
    I get "Hit: Trigger
    UnityEngine.Debug:Log(Object)
    ForwardDamage:SendDamage(Single) (at Assets/Scripts/ForwardDamage.cs:27)"
    And inside my Player the Trigger has a capsule collider
     
  10. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Okay it seems like you did not followed the steps in the UFPS pdf:

    Setting up UFPS and AI For Mecanim
    • Create a new layer at position 30 and call it LocalPlayer. Use this layer in the LineOfSight condition mask.
    • Disable hasCollisionTrigger in the Vp_FPController script under the physics.
    • Add a new Capsule Collider tot he player and set isTrigger to true
    • Add UFPSDamageReceiver to all enemies that should reduce an attribute.

    Everything else works the same way as in other examples.
     
  11. Pirogun

    Pirogun

    Joined:
    Dec 1, 2012
    Posts:
    31
    Thanks for the help! The one thing I am having trouble with is "Add UFPSDamageReceiver to all enemies that should reduce an attribute." Other than that the damage works perfectly (one way), Could you send me the UFPS demo so I can get it working both ways? Thank you for your help!
     
  12. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    You got a pm.
     
  13. SeriousRPG

    SeriousRPG

    Joined:
    Oct 21, 2013
    Posts:
    7
    I am trying to get the examples too (all of them). I run the Update Manager and it tells me my invoice is not correct. I am quite frustrated and am looking for the Patrol example (which I used to have when I installed 1.2 originally) that uses the AI (non character) controller to allow my character to randomly walk around without a person controlling it. I posted on your other forum too, but this one looks like it gets better response.

    Thanks,
    Sandi
     
  14. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Version 1.4
    - Tooltips for the action and condition fields.
    - You will not need to drag the AIRuntimeController script on the game object, just drag the new called "StateMachine" asset(AIController renamed to StateMachine).
    - Predefined StateMachines that you can just drag into the working editor window and it will place the states, paramerer... into the working StateMachine.(So no need to create same states for diffrent StateMachines).
    - Global and local(action fields, condition fields) parameters will be clean (Not more defined by a string and attribute).
    - Easy to extend actions, conditions and parameters.
    - You can use it not just for the ai but also for other things like character control, rts unit control, game control. So it is not longer only an AI System, but still more focused on that.
    - ObjectParameter for diffrent kinds of assets(AudioClips, GameObject, Transform, Materials...).
    - Conditions for all global parameters.
    - No diffrent states anymore, all states can be converted into actions.
    - No WaitForSeconds action anymore, same results can be achieved using a transition and a ExitTime condition.
    - State parameter error check(still needs to be improved, only in editor, no checks for runtime right now).
    - Support for Photon Cloud, all parameters except ObjectParameter can be synced.
    - Support for SoundManagerPro
    - New easy to understand examples, which give same result as the old.
    - Extended action and condition library(2d actions are still missing).
    - Removed Animator popups for now.
    - Easy custom script interaction using GetProperty and SetProperty.
    - SetStateMachine method to add a new state machine at runtime.
    - SetParameter method to set a value of a parameter outside of the state machine editor.
    - New tutorial videos(still missing some)
    - Unity trigger and collision events can be used in conditions
    - Examples moved back inside the package. No download manager any more.
     
  15. painkiller2007

    painkiller2007

    Joined:
    May 25, 2013
    Posts:
    44
    Hey Zerano,
    I think the UFPSDamageReceiver script is missing in the package.

    Could you upload it somewhere or put it here so i can test the AI with ufps asset! Thanks. :)
     
  16. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Hi, if you updated the package to version 1.4 there was a change in regards to the attribute. The creation of attributes was removed from the package itself to make a more generic system. However you in the IK Examples there is a simple HealthController script. Attach this script to your enemies and take a look on how the heath is handled in the IK Shooter state machine.( I am simply grabing the health value with GetProperty in AnyState and store it into a global parameter and check the parameter in the conditions.
     
  17. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Version 1.4.2
    - Bind the state machine to a GameObject->Scene. This allows you to use scene GameObjects in action and condition fields.
    - Improved GetProperty and SetProperty actions. Works now also with components. You have to enter the name of the component.
    - NGUI callbacks support in conditions. SetProperty allows you to change text or other properties and fields.
    - Warnings if a required component is missing.

     
  18. popawheelie

    popawheelie

    Joined:
    May 27, 2013
    Posts:
    23
    Could be just me, but in the Shooter IK example there was an error about instantiated object.

    In the Any state setting the GetProperty to "player" will fix this. Mine was set to Owner, causing the error.
     
  19. Navid

    Navid

    Joined:
    Sep 3, 2012
    Posts:
    39
    Hi Zerano,

    after i upgraded to the newest version the getHit animation doesn´t work anymore.
    How can i trigger "apply damage" state from your state machine.
     
  20. Pirogun

    Pirogun

    Joined:
    Dec 1, 2012
    Posts:
    31
    Hi Zerano,

    One of my AI has a bow and I am using the ForwardDamage script but I need a little assistance. When you set the direction of the raycast, you use transform.forward which works on level planes only so on a slope, the AI just hits the terrain.How can I modify this script to add a local transform.forward?
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. using System.Collections;
    4.  
    5.  
    6.  
    7. public class ForwardDamage : MonoBehaviour {
    8.    
    9.    
    10.    
    11.     public LayerMask mask;
    12.    
    13.     public float maxDistance=2.2f;
    14.    
    15.     public string methodName="Damage";
    16.    
    17.    
    18.    
    19.     private void SendDamage(float damage){
    20.        
    21.         Debug.Log("Message received.");
    22.        
    23.         RaycastHit hit;
    24.        
    25.         if(Physics.Raycast(transform.position,transform.forward, out hit, maxDistance, mask)){
    26.            
    27.             Debug.Log("Hit: "+hit.transform.name);
    28.            
    29.             hit.transform.SendMessage(methodName,damage,SendMessageOptions.DontRequireReceiver);
    30.            
    31.         }
    32.        
    33.     }
    34.    
    35. }
     
  21. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Thanks will be changed on next update.

    You can use GetProperty to get an external script variable like health, subtract x points from it and set it back with SetProperty. You can also use SendMessage to handle it in other script.
     
  22. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    80% off for a short time! Get it just for 10$
     
  23. karadag

    karadag

    Joined:
    Dec 23, 2013
    Posts:
    8
    Hello . Did you add 2d example project?
     
  24. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    No, it is in progress.
     
  25. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Update preview. This update is availible in my own store and submitted to the asset store. The price will also change back to 70$, when it is improved.




     
    Last edited: Jun 20, 2014
  26. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Using SceneInstance:
     
    SpectralRook likes this.
  27. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Just wanted to chime in and say that i started using this one hour ago and already up and running making ai stuff! Really easy and powerful package : D
     
  28. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Hmmm, something seems fishy with the send message stuff?
    If i have Int selected as a type and i put a number in the Int field i get zero if i do Debug.Log on the value in the function, but if i add a value in the Float field then it seems to work?
     
  29. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Ups thanks, will be fixed.

    If you want to make the change yourself, just change the OnUpdate method to:
    Code (CSharp):
    1.         public override void OnUpdate ()
    2.         {
    3.             switch (parameterType)
    4.             {
    5.             case MessageParameterType.Float:
    6.                 ((GameObject)gameObject.Value).SendMessage (methodName.Value,floatParameter.Value, options);
    7.                 break;
    8.             case MessageParameterType.Int:
    9.                 ((GameObject)gameObject.Value).SendMessage (methodName.Value,intParameter.Value, options);
    10.                 break;
    11.             case MessageParameterType.Object:
    12.                 ((GameObject)gameObject.Value).SendMessage (methodName.Value,objectParameter.Value, options);
    13.                 break;
    14.             case MessageParameterType.String:
    15.                 ((GameObject)gameObject.Value).SendMessage (methodName.Value,stringParameter.Value, options);
    16.                 break;
    17.             default:
    18.                 ((GameObject)gameObject.Value).SendMessage (methodName.Value, options);
    19.                 break;
    20.             }
    21.  
    22.             if (!everyFrame) {
    23.                 Finish ();
    24.             }
    25.         }
     
  30. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Great, thanx!
     
  31. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Just a small wish, would it be possible to allow for the use of GameObject->GetProperty directly as a Transition thing? I know its possible to grab it to a Parameter and then check that parameter but it will get messy very fast if i want to do that often. : p

    Edit: You have any idea how to get the Animator stuff working with the UMA system? I cant get the animations to fire : /
     
    Last edited: Jun 26, 2014
  32. SeriousRPG

    SeriousRPG

    Joined:
    Oct 21, 2013
    Posts:
    7
    Just uploaded the 1.4.2b and am getting an error:

    Assets/AI System/Scripts/Editor/PropertyDrawer/AnimatorParameterDrawer.cs(70,25): error CS0118: `StateMachine' is a `namespace' but a `type' was expected

    Any ideas?
     
  33. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Please delete the old AI System folder and import then the update.
     
  34. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Hello Zerano,
    What is Zerano AI? isn't it the same thing as Mecanim AI?
    I'm a bit confused about AI packages you produce :)

    Thanks.
     
  35. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    I do not have a package called "Zerano AI". There is one more that is called "Simple Ai", which is very simple used for lagecy animation and does not support mecanim.
     
  36. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    Is waypoint-system supported?
    That is, can NPC be set to walk in waypoints while player remains out of sight/distance?
     
  37. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Yes, there is an example waypoint system in the Default Examples folder.
     
  38. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    ?
     
  39. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    I will see what i can do. Currently i have worked on more Photon Support. The Animator in the UMA system should work the same way as other animator controllers. Do you get any errors or does it simply not updating the animator controller?
     
  40. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    I keep getting that it complains that the Animator is destroyed for some strange reason when im in idle mode and use the Animator.Set float to set the speed to zero, it works in other states like moving and stuff when i set the speed back again : /

    Got it to work finally, nothing wrong on your end as i thought : p
    Photon support sounds awesome : D
     
    Last edited: Jun 30, 2014
  41. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Hi i havent been fiddling around with this system for awhile and when i updated and also noticed a zombie tutorial i could not work it out is there any chance to make an updated zombie tutorial but with separate animations to the zombie because i have the zombie character pack from mixamo and they have separate animations in another folder so im guessing i have to send a message to the ufps controller. Also the demo of ufps don't really work either the bad guys don't kill the player so this ai update is not working for me anymore.
     
  42. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    What was the mistake?
     
  43. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Well, i had a lot of small stupid mistakes but the biggest thing was that i could not manage to change the runtimeAnimationController through script for some reason, updating UMA suddenly made that work though : )
     
  44. sirius_002

    sirius_002

    Joined:
    Aug 16, 2012
    Posts:
    65
    I bought this and am very interested in 2d AI samples.
     
  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    The state-machine editor window has a code conflict with uFrame. I don't have the time to find out what's going on, but it makes editing a state-machine almost impossible.
     
  46. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    I have a question ?

    I know you can switch to a different state machine. What if you have created 2 state machines (Follow, patrol). Is it possible to have transitional conditions to switch between 2 states. If not, can you add that feature. This will simplify things.

    For example if you have 2 state machines (Follow, Patrol) and then you create a master state machine (DwarfAI) that uses those 2 state machines. Let me know.

    Thanks
     
  47. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    In theory it is possible, you can just create a bool and save it in PlayerPrefs and get this bool from the PlayerPrefs in another state machine. This is the first solution i could think of, maybe there are others too.
     
  48. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Thats how i do it, i use one statemachine for every "behaviour" and it works pretty well, only thing is if you want several statemachines that cna be switched to fron the "sny state", then you need some extra script logic to keep track on the previous state.

    Zerano, any news on the networking update? Really looking forward to it : D
     
  49. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    It is already in the asset store, you can fully sync the ai with the photon cloud. I still need to make a tutorial on how to setup this.
     
  50. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Cool, will check it out : D