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. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi,

    Is it possible to implement the ai system in a turn based game? Like "think when is your turn"?

    Thanks
     
  2. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Yes, even if isTrigger is set to true it will already work. Raycasts can only be done on colliders.
     
  3. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    This is not possible out of the box without some tricks. But i hope with the next updates it will be possible also without complex thinking. it just requires some conditions and actions that will come for the regular system anyway in the next updates.
     
  4. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Hi I just can't get the follow state working. I get a error saying "NullReferenceException: Object reference not set to an instance of an object. I have done exactly the same as the tutorial. When player is less than 15 it goes into the follow state and also animates but it is all on the spot. It doesn't move towards the player. All i have is an Idle then a follow state. I have tried all the other states and they work.


    P.S. Really weird the demo AI Controllers work but when I copy Exactly them It still comes up with that error.


    ALL FIXED SORRY.
    I forgot to set the main speed on the follow sorry.
     
    Last edited: Feb 26, 2014
  5. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    437
    I bought this but now I have a major question... How can I make it randomly patrol on its designated "patrol path" ?????? thanks.
     
  6. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Hi has anyone worked out how a zombie works with this system. I have everything else working but the zombie won't kill the player. The player does kill the zombie. I asked once before and i thought it may have been with the new update but it's not. I use UFPS. And I was wondering how will you implement the AI system with another FPS control, like with "!Realistic FPS prefab files". Or even if I make my own FPS control, how would you make damage to enemy because I have tried the realistic Control but it did not kill my zombie. Thanks in advance.
     
  7. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    What do you mean by "randomly" patrol, if you use the patrol state it will patrol exaclty on the waypoints you created.If you want the enemy to walk randomly arround, you should use the Walk state.

    There are diffrent ways to apply damage to the enemy. So i realy do not know how Realistic FPS applies damage.
    Please read the "How to create new States?" section of the documenantion. Specialy the OnAttributeChanged trigger, where you can create an attribute and i also wrote how you can change this attribute in two diffrent ways.
    I do not have the Realistic FPS asset, otherwise i would write you a proxy script, on how i did it for UFPS.
     
  8. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    437
    Zerano, I want the enemies actually walking around on a "walkable" path where I have specified, not randomly walk anypoint it is walkable... so how can I achieve this to get multiple enemies to walk along a same path randomly without colliding to one another.
     
  9. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Ahh i see now what you want to do. This could be made with FinClosest action and a follow state. But this is a great idea for a state so i am going to implement this option for the patrol state in version 1.3.2, because version 1.3.1 is already submitted to the asset store with 2D support. So basicly it will be availible in the next version.
     
  10. Antigono

    Antigono

    Joined:
    Oct 20, 2013
    Posts:
    63
    Hi Zerano, could you share this with us?
    thank you very much
     
  11. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Glad to ear that. Thanks a lot
     
  12. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    I have the zombie dying with using UFPS but the zombie will not die with any other controller. I have read about the states so many times.
     
  13. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    437
    Alright, I am looking forward to it please please make a tutorial for that one also, I will need it I am sure others will too.

    Thanks appreciated :)
     
  14. dldnd

    dldnd

    Joined:
    Sep 3, 2013
    Posts:
    2
    When the update is a*?

    When the update is (1.3beta -> 1.3)?
     
  15. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    166
    Hi

    In one of the videos for line of sight you set the Target = Player for line of sight and distance. Can this be dynamically changed in code if I want the agent to attack another AI?
     
  16. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Well, when there are no bugs, so the more people test it the faster it will move from beta.


    It is written in the documentation pdf. In UFPS i just created a simple script. The bullet from ufps send a method called "Damage" with a float parameter to the hit object. But my method requires 2 parameters. So this is the proxy script:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class UFPSDamageReceiver : MonoBehaviour {
    5.     public string attribute="Health";
    6.     //Proxy method to transmit damage from UFPS bullet to the ai
    7.     private void Damage(float damage){
    8.         Debug.Log ("Sending");
    9.         SendMessage ("ApplyAttributeDamage", new object[]{attribute,(int)damage});
    10.     }
    11. }
    12.  

    Yes it can be changed in code, but you can also do this inside the editor. Just create a new global parameter with a tag of the ai and store it into the created parameter then you can do conditions based on it.

    Here is how you can change it inside code:
    Code (csharp):
    1. GameObjectParameter param = owner.GetParameter("Player") as GameObjectParameter;
    2. param.Value = newGo;
     
  17. dldnd

    dldnd

    Joined:
    Sep 3, 2013
    Posts:
    2
    i want 1.3
    and

    (if and if ) => action
    (if or if) => action
    action1 => action2 or action3 ( random)
     
  18. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    This is possible with transitions to states:
    (if and if ) => action
    (if or if) => action

    I will add random transition to states.
     
  19. uansgheps

    uansgheps

    Joined:
    Dec 5, 2012
    Posts:
    11
    I Zerano,
    I have imported latest version of your package in my Unity 4.3.4 but there are many compilation errors like this one:
    Assets/AI System/Scripts/States/Triggers/BaseTrigger.cs(6,10): error CS0246: The type or namespace name `Trigger' could not be found. Are you missing a using directive or an assembly reference?
    How can I do?
    Thanks
     
  20. Also

    Also

    Joined:
    Jul 17, 2013
    Posts:
    16
    Yeah, I'm having the exact same problem, I get over 90 errors like that.
     
  21. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Can you please check if the script TriggerAttribute.cs is located in your project. It is in the same folder as the BaseTrigger.cs script.
    I would suggest to delete the whole AI folder with examples and reimport the package again. Please let me know if this helps.
     
  22. Also

    Also

    Joined:
    Jul 17, 2013
    Posts:
    16
    I have both files in the correct folder and have removed/reimported the package and it's still giving errors. Here's the complete log of errors I'm getting:

    BTW, if i create a new empty project and import the package, examples etc it works just fine.
     
  23. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    very strange, it seems like it does not recognize the attribute class, the strange thing is that it works in an empty project, so very hard to say what is going on here. I will make some tests.
     
  24. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Hey,

    Current mecanim AI system only supports and works on Animator component.

    Is there any plan to support legacy Animation component?
     
  25. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Hi I still having trouble with doing a zombie AI with this system. I am using the UFPS and you can kill the zombie but the zombie will not hurt/kill the player. I think maybe use the send message "Damage" on the attack state but I can't find out how to use the send message action though. So if anyone have worked out how to get a zombie killing the player pleeeeeeeeeeeeease post a tutorial or tell me how the send message action works.

    Thanx in advance. Been trying other systems as well but more or less the same thing happens still. Once i work out how the zombie can kill the player then i can move onto doing something else.
     
  26. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    In the asset store AI is says it needs 4.3.4. 4.3.3 works fairly well for windows 7. Do I have to get 4.3.4 to run AI?
     
  27. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    In theory it would work with some custom actions. I have not written those actions, just because of the asset name "AI For Mecanim". Maybe in the future i will write those and just provide an extra support package for those.


    I can make a tutorial, how you could do this.

    Well it would work with 4.3.3, but i am using the latest unity version and so you would need to downgrade the package by yourself.
     
  28. uansgheps

    uansgheps

    Joined:
    Dec 5, 2012
    Posts:
    11
    For testing purpose I have created a new project like Also has suggested and in fact compilation has succeded, but I have a big project and I would like not to recreate all from the beginning ....

    With previous version of your package all works fine.
     
    Last edited: Mar 3, 2014
  29. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    If you want i could take a look with teamviewer over it.
     
  30. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    Creating a AI controller. Have 2 actions -- Idle and Walk. A transition from Idle to walk. Click on conditions, gameobj, distance. No logic appears. Using AI system - Overview. Windows 7 not a Mac. Does your package work for Windows 7?
     
  31. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Do you get any error in console, i am working here on windows 8.1, but it should not have anything todo with the operating system. Are your conditions folded out(Just click on the Title where it says "Conditions")?
     
  32. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    Hi Zerano,

    Great Product, just wonder if it's possible to set more than 1 target.

    The idea is: if idle for X amount of time go and do something else, Ah, I think I've just thought of way of doing this as I type - so for anyone else...

    Set Target as Player in Idle.
    If Idle for more than X and the Player hasn't come into range use "Exit time" to Jump to a second Idle state with Set Target to a tag (in my case the tag is canMine - so a rock that contains ore could be tagged with this)
    If the rock is within X distance follow it and the set a mine animation for X seconds then set it to go home, if not switch back to looking for the Player.

    Which then adds another question, is there a way of targeting the Spawn location (or home). Or would I have to create a tag for each location and abandon the Spawn prefab I have.

    More than 1 target would still be handy as we could then jump out of the mining routine if the Player came in range even though we're targeting the Mine object. Something Like set Target1 = Player, set Target2 = canMine, set Target3 = Bed

    And on that last one (Bed) can it pick up a time of day from a script, or if not could a future version so we can do time based animations?

    Really this comes down to can we send variables to the AI System and can we send a customized message out?

    Sorry that's a lot of questions but this really has made a huge difference to the development pace already so I'm really pleased with it.
    Potentially the additional targeting and time of day this could create Oblivion/Skyrim type NPC characters with jobs, and "time of day/day of week" actions.

    Truly astounded by how good this is already - Thanks
     
  33. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    It is already possible to make more then one "target", but each of them would need an extra tag. You can for example also tag all mines with "Mine" and let your ai find the nearest one. But if you want to store diffrent targets, you would need for each type a tag.

    My suggestion for better performance if you do not need to change the target, so basicly if there is only one player or one mine:
    Create a Simple State just for setting up targets and set this state as default. Setup your targets as needed by FindClostest, FindChild, FindGameObject. Create a new Simple State, that will behave as Idle. Make a transition from first state to idle and add for each of your targets a condition IsNull with an equals as false. So you will switch to the Idle state when all your targets are found.
    Now you can create again two follow states lets call them "GoToMine" and "Follow Player". Make a transition from Idle to "GoToMine" and add a greater then distance condition for the player target. This means if the player distance is greater then x we transition to GoToMine. Make a transition back to Idle with a less then distance condition for the player. So if the player comes nearer and if the ai is in "GoToMine" state go back to idle. From idle you can make a transition to Follow Player and set there your distance conditions.

    Okay lets say the player is outside of range.

    You can now create a new State and call it maybe "Mine", in this state the ai will mine ore or i do not know. so make a transition from "GoToMine" to "Mine" with your mine target distance condition. For example if the distance is less then 2 go to the state "Mine". In the "Mine" state just make all the animation stuff you want, and make also a transition back to the first Idle where you still check for the distance of the player so if the player comes nearer, the ai will transition back to idle and from there it will choose the Follow Player state.... You can extend it mostly to infinity hehe.
     
  34. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    Hi again,
    is there a new version out?
    I bought the beta and its on my list of assets:
    AI for Mechanim v1.31 Beta

    but it doesn't have "There is a new version available" next to it
     
  35. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    Wow - and fast response times as well :¬)

    Going to have to put my thinking head on to plot out how the interactions work, also wondering this...

    Is there any difference between unity free and pro as far as AI System goes?

    I've gone through the tutorial documentation that's bundled within the asset package and it doesn't mention the FindClosest so I looked at the documentation link on the asset store and it's different to the bundled one.

    That does mention FindClosest but it also says the Inspector should show Actions, I'm not getting this so I just wondered if it behaves different with Free Unity - that's what I have - free 4.3.4f1

    I'll have to get Pro at some stage but I wanted to be well down the development stage before that so I pay for the latest possible version without having to add upgrade costs as well.

    Or have I missed something and just need to add a certain script/package in before it shows?

    Oh and really mean it about the Time of Day stuff, would be great for the Ratkin Slave to shuffle off to bed at the end of the day. Adds all kinds of possibilities with quests.
     
  36. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Yes version 1.3.1 Beta is the latest version right now.

    There is no diffrence in the workflow. The only diffrence is that you can not use IK stuff in animator actions and the OffMeshLinks do not work in unity free. Everything else is the same. It sounds like you have not the newest version. I moved the properties area in to the inspector. so basicly there is only the graph in the ai editor window and all settings in the inspector. Now i understand that ou talked about SetTarget, this was needed below version 1.3, now there are diffrent actions for this.
     
  37. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    Odd, I did download it when it was in the unity sale (because it had such good reviews), a long time before I needed to use it but I thought I'd got the latest version. As nomax5 is saying there is no upgrade available in my download assets window, although I don't appear to have the full 1.3.1 version. Mine is only reporting 1.3 beta not 1.3.1

    Not sure why my version is reporting 1.3 when you said 1.3 was the version this is fixed in!

    Thanks for the fast response times and I'm sure it's not your issue but one with my Unity account.

    Even with the issues I'm having I still think this is the best Asset I've brought to date, it's the perfect addition to Mecanim and Mecanim is the best way to apply animations, but it's more than that, if I can get the latest version (the gods/gremlins of Unity download assets willing) it appears to make Finite State Machines amazingly simple.

    Good work, hope I can get the latest version, might try a new project and see if the downloads the right version.
     
  38. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246

    I really neeeeed a tutorial thankyou. If it was a shooting AI i would have been fine but because I still want a zombie, i really have no idea how it could kill the player.
     
  39. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    The new tutorials are good(week old). However, I hear an annoying click at the beginning. Could you please try to remove it.
     
  40. uansgheps

    uansgheps

    Joined:
    Dec 5, 2012
    Posts:
    11
    Maybe something was wrong in my project configuration, I will try to export all my scripts and resource to rebuild a new project, I thing this is the best clean solution. Thanks for now.
     
  41. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Okay, i hope it works out for you, if not just let me know again.
     
  42. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    Zerano, do you think you could make a short movie where you create a Mecanim controller(simple) and a AIcontroller. I don't see the relationship between the 2 controllers.
     
  43. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Sure, i will make it for the 2.5D AIController/Animator Controller, since the actions are ready but i have not made any examples yet if this is okay. If you need it for 3D i could make one also...
     
  44. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    Great. Do one for 2d and 3d. Thanks.
     
  45. wendymorrison

    wendymorrison

    Joined:
    Jan 6, 2014
    Posts:
    246
    Just wondering if a zombie tutorial using UFPS is coming soon. Am still not getting anywhere. I've tried other systems but this one is the best 1. I,ve actually got a zombie moving and following as well as dying but still can't get it to kill the player.
     
  46. Darren-R

    Darren-R

    Joined:
    Feb 11, 2014
    Posts:
    66
    Heya,

    Thanks for a great asset! I'm having some issues working out things due to a lack of much documentation.
    Can you give me any pointers on how the "Apply Root motion" tick box in the follow state can be used? When I click it my character just runs in a straight line and doesn't follow my target.
     
    Last edited: Mar 5, 2014
  47. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    Just speculation but are you also following the BergZurg tutorials?

    I am and I got the same issue, well this is the Pathology of the error:

    Downloaded this asset when it was on Sale as I was struggling converting the BergZurg scripts to allow Mecanim. At the time I was reworking the player controller to work with Mecanim so I left AI System untouched.

    Once I got the Mecanim controller for my main character sorted (took weeks) I came back to AI System. Imported and created a basic Enemy attack in no time at all. Was very impressed but wanted to have more than 1 target.

    Turns out I wasn't up to date with the latest version and more than 1 target is possible 1.3.1, so I upgraded and then hit the same issues you have - exactly the same issues.

    Start a new project and it's fine until I reload all the BergZurg scripts. At that point it fails with the same error messages. I tried manually deleting each file but there are a lot of script files in BergZurg so I haven't managed to track down the area causing conflict and, in truth the issue wasn't there in the earlier version of AI Sysyem.

    What I have read is that "namespace" can be broken very easily. I could well be wrong but it seems a combination of the 1.3.1 upgrade and either BergZurg (or another script) causing Namespace to break.

    I think I probably need to step away from the BergZurg scripts at some point anyway but would be interested to know if the issue is the same as it would be great to combine the two for a while longer.
     
  48. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    And after copying files back in one at a time from BergZurg I hit the issue (first time at least) on the Attribute.cs script, Shown here:

    ================

    public class Attribute : BaseStat {
    new public const int STARTING_EXP_COST = 50;

    public Attribute()
    {

    ExpToLevel = STARTING_EXP_COST;
    LevelModifier = 1.05f;
    }
    }

    public enum AttributeName
    {
    Might,
    Constitution,
    Nimbleness,
    Speed,
    Concentration,
    Willpower,
    Charisma
    }

    ================

    This is only a guess but the smoking gun appears to be CategoryAttribute.cs:

    ================

    using System;

    namespace AISystem{
    [AttributeUsage(AttributeTargets.Class)]
    public sealed class CategoryAttribute : Attribute

    ================

    Did that change from earlier versions.

    Really just learning Unity so I could be wrong.
     
  49. Mmmpies

    Mmmpies

    Joined:
    Feb 19, 2014
    Posts:
    31
    Well I got the Project and Scene working from the original one that failed.

    I renamed the Script file from BergZurg (called Attribute.cs) to BZAttribute.cs and then worked through each errors that it caused and it now opens OK.

    I think really just consider making scripts and variable names unique, I don't mind how but maybe use your initials or a cut down version of your product name to prevent Unity, which has a lot of differing Devs working on it, from hitting this kind of error.

    This is no reflection of how good this product is because, WOW, just so impressed.

    hope this helps
     
  50. DevionGames

    DevionGames

    Joined:
    Feb 22, 2010
    Posts:
    1,624
    Hello, great that you sorted this out, the Attribute class is a System.Attribute class, so changing it to:

    using System;

    namespace AISystem{
    [AttributeUsage(AttributeTargets.Class)]
    public sealed class CategoryAttribute : System.Attribute

    should also fix it.