Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

ICode (AI For Mecanim 2.0)

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

  1. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Great.. I will try it and let you know the results. Thanks
     
  2. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    You say it is simply to Mecanim. I all ready paid $1500 for Unity why should I buy yours?
     
  3. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    This is not the mecanim system! It looks pretty the same but this is an ai system that works with the mecanim system, it would not exist without mecanim. You should check the video above or on first page or maybe read the documentation pdf.

    This is basicly a system to get mecanim working without(less) scripting. Instead of creating a script and add all the code(find target, check distance, play a sound, trigger a mecanim state(play animation), Instantiate and many more), you can create your ai states with the ai controller editor and execute all this from it.

    I hope this helps to understand what it does.
     
  4. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Thanks, i just updated the package in my store. I also added some ik actions and an example scene, the ik actions are not fully finished though.
    It seems like you are the only one at the moment, who gives some feedback, this realy helps to improve this system.
     
  5. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,446
    This is killer... and I am thinking of using something like this for my fighting game, like programming hit reactions... but I will just watch the video...
     
  6. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    When you write your own states how much work is required to get them to show up in the panel? Also, what kind of format is the AIController? Is it human readable? (like XML or something)
     
  7. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Thanks, let me know what you think about it.

    There is no work required at all if you extend from an existing state, it will add your state automaticly to the create states menu and also show up in the properties and graph with all the properties you add in the constructor of your state. There is some more todo if you want to add a new condition or an action, you would need to add a few lines(based on your needed variables) to the property drawer. If you know how to copy&paste and know what is a float, int , Vector3...this will be not more then a few minutes maybe seconds, depends of course how you will handle the condition/action.

    The AIContoller is a .asset file and the values are also changable in the inspector. It should be possible to make an exporter to xml or other format, but this is not part of this package.
     
  8. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,446
    This is very impressive... I am already getting ready to play around with mecanim this weekend when I get my model rigged. But for this AI, how would I set this up for fighter against fighter? How many trees can I have for the increasin difficulty? How would I set it up like a fighting game...
     
    Last edited: Jan 9, 2014
  9. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    This system supports only one tree, i do not know why you would want more trees, since if you would have more then one AIController you would still need to interact between those. Maybe for reusability it is not bad to be able to replace the AIController at runtime, thanks for bringing up this idea.

    It is not easy to say how you would setup an ai for a fighting game, there are many types of a fighting game i would say. Are both fighters computer controlled? Is it 2.5d or 3d? However i would love to help you to setup something like this with some more information. Maybe there would be some features/actions/states required that i simply did not thought about and would integrate it for all users. This is an offer for other users too! So if you can not realize something just request it!(It does not mean that i will 100% integrate it, but i will look over it and if it is usable for all users, i will try it.)
     
  10. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,446
    The game I am working on is 1 v 1, and local multiplayer... there is also a story mode where you face off against the computer which gets progressively diffucult... and the game is 2.5D. I also have systems in place such as a meter that prevents players from spamming moves... and I would love to have the AI "learn" how you play
     
  11. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Well i have not tested it with 2.5d at all. The learn thing is not integrated out of the box also at the moment.
     
  12. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    I have just updated the demo with 2 new scenes(IK Actions) that will come in the next update.
     
  13. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    I just uploaded version 1.2 to my store and submitted to the asset store.

    • SetRandomFloat does not exists anymore, please use SetFloat and choose
      type Random.
    • Added many types of SetFloat.
    • Added CrossFade
    • Added SetLayerWeight
    • You can now instantiate at child transform.
    • Added more conditions for target(IsNull, Attribute,IsName, InTransition)
    • Added GetBool and GetFloat condition
    • View condition can have true or false for better controll.
    • Root Motion can be applied for each state.
    • You can destroy child transforms now.
    • Added IKActions for unity pro users.
    • 4 new scenes(IK,IK Aim,Root Motion Shooter,Root Motion Shooter Auto)
    • Internal improvements
    • Price change back to 70$

    Here is a new Auto Shooter Demo.

    Thank you very much who purchased it during the trial price! I did not expected such a success. Within a few days it is in the top paid of ai section.
     
  14. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    (Please note UFPS+AI demo is not part of this package, but can be recreated using UFPS and this package)
    UFPS+AI System Demo
     
  15. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Version 1.2 was just accepted by the asset store. Many thanks for the rating and reviews in the asset store.
     
  16. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Grabbed it on a whim and seems like a solid asset. Just to facilitate debugging it could use some more logging options (e.g. something to toggle dumping decision data to the console on every update). When your AIs aren't behaving more info lets you figure out which transition isn't firing.

    Also, crash report. Setup: Newest version of Unity, closed Unity while the AIRuntime Controller window is still open and Unity crashed with Access Violation message over and over until I moved the AI System directory out of the project, let Unity start up, and moved it back in.
     
  17. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Thank you for your feedback, i am going to look at the closing problem, yes i also thought that it could have some more debugging information. Because at the moment if a state transitions from one state to another and then back again, you just do not see it.
     
  18. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Zerano, I have implemented the way you have suggested and everything better. I am running into strange problem. The view is not working properly. I have to increase the scale of my player to make it work, I am using [view, 180, player] as my action and also the enemy can see from behind the walls. Do you have any suggestion or what I am doing wrong. Thanks.
     
  19. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Keep in mind if your scale is way off from what Unity recommends (2-3 units tall players, etc) you are going to run into problems with lots of things. Unity hates very small and very large scales.

    Zerano, I'm digging this a lot but I'd love to see some changes to how some of the Base classes work. Those big switch statements are awfully inflexible. It would seem like a good idea to instead make the various conditions all implement a common interface (like how your states work) and make the conditions distinct classes. That would make it a lot easier to extend and add functionality to your system without losing changes when I update.

    Also, another bug report. Attempt to add a patrol path to the Patrol state and received the following error:

    "NullReferenceException: Object reference not set to an instance of an object
    AiEditorWindow.DrawNodeProperties () (at Assets/AI System/Scripts/Editor/AiEditorWindow.cs:156)
    AiEditorWindow.OnLeftGUI () (at Assets/AI System/Scripts/Editor/AiEditorWindow.cs:54)
    TwoAreaEditorWindow.OnGUI () (at Assets/AI System/Scripts/Editor/TwoAreaEditorWindow.cs:41)"

    Looking at the script I figured out it was because since loading the scene I hadn't centered the camera anywhere (e.g. select and object and hit "F"). Once I did that it stopped throwing the error.

    Might want to throw an if statement around that lastAcriveSceneView.camera call to check for null.

    In a related note, a "Wander X units from starting point" state would be helpful just for some generic shuffling.
     
    Last edited: Jan 15, 2014
  20. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Hi, well pleasse select also the layer of the wall and remove the layer of the enemy. I set the layer of the enemy to "Enemy" and have Layer for the wall as "Default". My condition looks then like this:

     
  21. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Thank you for the error note, going to add a check right now. Seperting conditions, state actions, ik actions is on my todo list.
     
  22. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Zarano, I have tried that and it seems to be working. I am still having issue with my scale. I have to set my player scale to 3 in order to work which is not acceptable I want to make it work with scale = 1. I do not know why is it happening ?
     
  23. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    One more thing "Path finding" Is that supported ? If I can resolve those 2 issues I should be able to proceed on in my game
     
  24. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Zarano. I think I have figured it out. To fix the scale problem I have increase the height of a character controller and to fix the path finding I have re baked the navmesh. You can still give me any advice if you think there something I need to know.

    Thanks
     
  25. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Hi, sorry for my late answer, well, rebake the path is always needed when you add something collidable to the scene.
    For checking the lineofsight/view, i am using a simple linecast with 1 unit offset from ai to target, this can make some problems if your target collider is smaller then 1 unit.
     
  26. popawheelie

    popawheelie

    Joined:
    May 27, 2013
    Posts:
    23
    Awesome asset!


    Is there any plans OR any way to copy states?

    Also, regarding setting up damage. I'd like some more info/quick tutorial on setting up damage to the AI and player received damage.
    Basically, I'm trying to set up environmental damage to an AI, like a rock falling, having some trouble trying to access the AI health floats/Ints.

    Cheers!
     
  27. XilenceX

    XilenceX

    Joined:
    Jun 16, 2013
    Posts:
    122
    I love the idea of an AI setup system that is controlled like Mecanim. How does local avoidance work for this asset? It's always important for me since there are many melee attackers in my games. Also what about multiplayer support? Can the AI pick between 2 different players and attack the one who is closer or something like that?
    Oh and last but not least, there are quite a few helpful Playmaker actions for Mecanim, are those supported in this asset too? Obviously only the ones that are relevant to AI, but this would be awesome! :)
     
  28. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    I agree that copying states would be good. Creating complex machines takes some time and anything to speed up the process would be beneficial.
     
  29. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    At the moment it is not possible to copy/paste states, but i am going to add this in the next update.I also think it is usefull.
    You can access the Attribute by first getting the AIRuntimeController maybe via GetComponent and then there is a method GetAttribute(string attributeName) where you will get the attribute. On this attribute you can do operation like Cosume or Add.
    I can make some example triggers to show how you can use it.

    I am using the default unity pathfinding since it does not require unity pro anymore. There is no multiplayer support out of the box(no sync), but the ai can pickup the closest player. It is not realted on the player, the target can be anything. Checkout the Auto Shooter demo(Enemy vs Enemy) . PlayMaker is currently not supported.
     
  30. popawheelie

    popawheelie

    Joined:
    May 27, 2013
    Posts:
    23
    That would be great. Thank you so much.
     
  31. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    I assume this just calls pathfinding so if you are using pro you can get local avoidance right?
     
  32. Eyehawk

    Eyehawk

    Joined:
    Dec 24, 2012
    Posts:
    288
    Hi this looks very cool! Is it possible to integrate other 3rd party pathfinding - e.g. Aron Granberg's Astar with this asset?
     
  33. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Yes it just calls SetDestination

    This will not work out of the box, you would need to rewrite some things. :(
     
  34. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Ouch that's unfortunate. Ideally this would be perfect if it worked with A* Pathfinding Project. If possible I suggest integrating it and RAIN as they're the two most popular path finding assets available. Otherwise maybe a documentation as to what we need to modify (where the pathfinding in Mecanim AI is handled).
     
  35. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
    I've used the tutorial video you provided on Youtube for this and it's great! However, my enemy seems to be running on the spot. I'm scratching my head here why it's doing this. He follows the player every now and again but most of time he ignores the player and walks on the spot. Any advice?
     
  36. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    If you have "Apply Root Motion" checked and your enemy does not have root motion data, like the included ratkins, your enemy will walk on place, so uncheck "Apply Root Motion" in the ai editor. It could be also that there is no navmesh baked, but you would get an error if you forgot to bake it. Also if you add an action and set the "speed" parameter in the animator controller while your enemy is in idle state , he would also walk on place.
     
  37. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
    I've tried using your Ratkin anims instead and unchecked the Apply Root Motions, still running in place, the speed parameter is at 0 during idle and the navmesh has been baked yet it's still walking in place. For some reason it's now not responding to the follow command. This is really making me scratch my head, not even the anims from the example want to work :/

    Edit: I've tried making an Attack AIController using your tutorial, the player is tagged "Player" and layered under "Player" and the enemy is stuck on Idle :/
     
    Last edited: Jan 21, 2014
  38. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Have you added SetTarget in actions? If you want you can upload your AIController and i can take a look on it.
     
  39. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
  40. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Zerano, I was wondering if you have a example for a melee attack. When the enemy hit you with melee weapon I want player to loose some health. If you can point me in the right direction. Thanks
     
  41. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    I just check your AIController. After changing the view condition mask to iclude player all works fine.
     
  42. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    You can send a message and then write a new method where you handle it. Checkout the attack example, there is a script called DamageReceiver.cs attached to the player and i am sending a message in the attack state. The state is set as a parameter in the SendMessage and you can get damage and other properties from this state.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DamageReceiver : MonoBehaviour {
    5.  
    6.     private void OnGetHit(AttackState state){
    7.         Debug.Log ("Damage " + state.Damage + " Hit Chance " + state.HitChance);
    8.     }
    9. }
    10.  
    $SendMessageInState.png
     
  43. fhl41

    fhl41

    Joined:
    Jan 8, 2014
    Posts:
    14
    UFPS+AI System Demo how you did this can you explane it, all i can is ,they do is walk to player walk around me and hit me on the head they are not shooting at me ,i use the Root Motion Shooter example i whant that they shoot at me
     
  44. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
    Thanks! Where about is the view condition mask? I've just been trying to look for it and couldn't seem to locate it anywhere.

    EDIT: I've found it however the enemy follows the player on the spot still.

    EDIT EDIT: Done it! Thanks man! Expect a review real soon! Thanks for your help and support!

    EDIT x3: I've noticed for a few times now that creating a new project with AIController asset that once you close and open the project again, Unity won't run, you have to delete the folder and re-import the asset Unity starts up. Not really sure, but I'm reporting the bug that happening for you.
     
    Last edited: Jan 22, 2014
  45. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Yes, i will try to find some time today and remake it recoding it.

    It is a bug, if you have the AI Editor window open and close the project, unity does not open again. I will try to fix it for the next update, for now you have just to close the AiEditor window before closing unity, sorry for this.
     
  46. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
    Thanks man. Your support is legendary.
    One final question: I've got a third person character and I want the sword (That's a separate entity to the character but still attached to the characters animation) to trigger the "Gethit" part of the AI tree. I tried basing code from the "Gethit" scene you included but after tinkering lots, I didn't get anything (As it's based on a first person GUI texture), how would I go about making the sword trigger the "GetHit" AI box? Sorry about all these questions :p
     
  47. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    There are many diffrent ways. The easiest would be maybe to just add an animation event to your player attack animation and create a simple script like this:

    //SwordAttackDamageSender.cs attached to the player (Please note this is not tested, but in general should work)
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SwordAttackDamageSender : MonoBehaviour {
    5.     //Damage that will be applied to the enemy.
    6.     public int damage;
    7.     //Maximum distance from player to the enemy, where the damage
    8.     //will be applied.
    9.     public float maxDistance;
    10.     //Health attribute of the enemy, you can create it in the AI Editor.
    11.     public string healthAttribute;
    12.  
    13.     //This method will be triggered from the animation event
    14.     //So add an event with the name SwordAttack to your players
    15.     //sword animation.
    16.     private void SwordAttack(){
    17.         RaycastHit hit;
    18.         //Send a ray from players transform with his forward direction
    19.         if(Physics.Raycast(transform.position+Vector3.up,transform.forward,out hit,maxDistance)){
    20.             //We hit something so lets check if it is an enemy with an AIController
    21.             AIRuntimeController behaviour= hit.transform.GetComponent<AIRuntimeController>();
    22.             //Check if we hit the enemy
    23.             if(behaviour){
    24.                 //Yes we hit the enemy, so lets get the health attribute
    25.                 BaseAttribute defenderAttribute= behaviour.GetAttribute(healthAttribute);
    26.                 //Is the health attribute defined in the AI Editor?
    27.                 if(defenderAttribute != null){
    28.                     //Yes the attribute is defined in the AI Editor,
    29.                     //so lets consume the damage from it.
    30.                     defenderAttribute.Consume(damage);
    31.                 }
    32.             }
    33.         }
    34.     }
    35. }
    For the next steps you can checkout the GetHit example, i only copied it from there.

    Then you can add a condition when the Attribute is changed to your AIController:
    $AttributeChangedCondition.png

    And finaly create a state where the GetHit is handled:
    $TriggerGetHit.png
     
  48. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Thanks.

    I want to write a review, but I am not able to do so since I bought the asset from your store. Is there anyway to buy the asset from asset store without paying again.
     
  49. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Sorry the only way for this would be if i refund you and you repurchase it from the asset store. This is not a problem in general, but i would need to pay 30% to the asset store from your purchase. I do not know if you purchased it during a discount time, which ended already and the price on the asset store is at the moment also at 70$, i have no ways as far as i know to give discount coupon code on the asset store.
     
  50. RyuuzakiBjorn

    RyuuzakiBjorn

    Joined:
    Jan 21, 2014
    Posts:
    25
    The code runs without fail however the problem I'm having is getHit is assigned in the AI controller to "Idle" and "Follow Player" and "Attack", When I try to add the "State Action" get hit to the transitions to getHit, it applies this getHit to all transitions to and from the state for some reason.