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

[RELEASED] Finite State Machine Version 2.0b by Lost Zombie Studios $15

Discussion in 'Assets and Asset Store' started by Danny_HoW, May 7, 2012.

  1. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Link : See it on the asset store !

    Read Me : ReadMe in PDF Format

    Company Website : Lost Zombie Studios

    Finite State Machines have been one of the best ways to control and power a project
    whether it is a light-switch being on or off to AI which could have tens of states to even
    Game Controllers that could technically have hundreds of states. The LZS Finite State
    Machine can do all of that … and ! has a few nice features you wont get elsewhere.

    Why so cheap a Cost ?
    Lost Zombie Studio’s is a small and independent game developer from Scotland. We
    are between 3-10 members depending on project and we of course understand the time
    and cost constraints that go with being a small studio. This is why we have decided to start
    releasing a number of asset’s that we feel can help other small studios like ourselves to get
    their projects going in a good direction, and get them out there at an affordable
    price(knocked down from the advised price from unity store. The first of these assets is the
    Finite State Machine.

    Why ? Why our finite state machine over others ?
    We have looked through the asset store at what it has to offer in terms of other FSM.
    They are priced around the $30-$50 mark for what we feel are assets that lack in some
    core mechanics that might be useful. We also talked about how BIG scripts and classes
    can get that use many states. Imagine a game controller that has 30 states and all these
    states are written into the original class as “States”. Our FSM splits these states up for
    you into separate script files and thus can be kept to very small files that just do their own
    job or task. This is also great for working with others where tasks on the one mechanic may
    be split between multiple people and they can concentrate on separate States, saving any confusion
    between versions of one large class. We have added in the “Pushing” and “Popping” of states
    that some may know from the functionality of the Unreal Engine’s own state machine and worked
    it into ours in a nice, fluid way. We also have Object Handling between states which is something generally
    overlooked by FSM’s and is a great way to save time and calculations.

    Feel free to ask any questions
    Thankyou
    Daniel Gallagher
    Programming Lead
    Lost Zombie Studios

    Lost Zombie Studio LIMITED is registered in Scotland. Company Number. 409159
     
    Last edited: Nov 28, 2013
  2. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Sold a few in the last 24 hours and just wondered if you cought it could you give a little post and let me know what you think, thankyou
     
  3. DavidB

    DavidB

    Joined:
    Dec 13, 2009
    Posts:
    530
    I bought the package and gave it a look over, looks good! Nice, simple and pretty robust from the look of it. When I have some time to play with it and produce something I'll report back :D
     
  4. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Good to hear it David ! Feel free to email me anytime and I promise to get back to you sharp. My email is in the readme
     
  5. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Please remember to review and rate this if you buy it thankyou :)
     
  6. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    New Update coming soon, watch this space :)
     
  7. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    24
    I read through your pdf and have a few questions. I've been learning about fsm's for a few weeks so I'm rather inexperienced with them but I have an idea of what I'm going to need.

    I have an enemy that seems to really need 2 fsm's. One for movement, and one for attacks, possibly a third in the future but lets say two for now.

    -Movement and attack states may change at any time independently. IE: start lerp to player > start weapon swing anim > stop lerp mid swing

    -The attack state may ask that the movement state change. (your pdf example seems it could this with one fsm but would it be similar if there are two fsm's)?

    -An outside event may signal one or both to change state abruptly or once they have finished changing states. Does yours support this and if not, any idea how I might add it in with something like delegate events? I'm just not sure if those would tie into the state code directly or into the fsm class...


    Overall it seems I would need a base class to handle/manage the logic of changing in and out states between the two fsm's. Does that sound like the correct approach or should the two fsm's somehow communicate with each other? Sorry if my questions seem silly :p By the way I found your pdf to be very clear and informative and will likely buy your fsm soon.

    Thanks for any help!
     
  8. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Hi Frip, some good questions there and this is basically all along the lines of programming Gameplay Theory I suppose. Would be great to chat more about it in the hope I could possibly help with any thoughts and advice. Just to clear up a couple of things before I begin to answer. The 2 FSM's for attacking and for moving ... What is considered states of attack and what is considered states of movement ? The less code and less calculations you have going on the better obviously and this seems like something that could maybe be brought down into one FSM. Especially in cases of enemies where you could have a LOT of them in the one scene. Could you give me a better idea of why you have 2 FSM's and what they both control ?

    To answer your question straight up though, using my code your Objects could have unlimited state machines. I currently, for example, have an enemy class in one of my projects which has 2 FSM's. 1 is the controller which powers what the enemy is doing. The other is the Animation FSM which controls which animation to be in and when to run animations. (Its nice to split these up as they can be moved between objects) I then have a bridgeing class which constantly feeds data from the controller to the Animation FSM. This works perfectly fine and isn't too hard to setup and I would be happy to give you further explanation and help with anything you need :)

    Try to give me a bit more detail on your problem and if possible I will let you know how it can be solved with my code. By the sounds of it though it wouldn't be difficult at all for you to setup and maybe I'll look into doing an in-depth example of multiple FSM on a single object.

    Cheers !

    P.s. sorry for the wait on the reply

    P.p.s ... I read your post again and you have made it clearer than I thought you had :) I think this could be handled pretty simply by the example I breifly spoke about there. You would have the Moving State ....

    Active (if see player, gotostate pursue player) ... Seen Player ! ->
    Pursue Player (run towards player ... if (close enough) set closeenough to attack ->

    your animation FSM is constantly looking for close enough to attack, when it sees that that is turned on it "Pushes state SwingArmsAttack" (this Push is the abrupt change you mentioned, without having to wait for any time to change the state)
    this constantly runs through this state in the animation class until it sees its not close enough, at which point you just Pop out of that state.

    So whilst your movement FSM is still pursueing player, your animation class is animation the enemy to look like hes attacking. Then all you do is some kind of attack calculation whether that be collision detection on the enemies hands or weapon or whether it is simply everytime it runs the animation it damages you. That bit is upto you.

    Theres other ways to look at this though. You could simply have the animations popping off in the movement FSM and only ever need 1 FSM ... animation's will constantly run until told to stop so they can quite easily continue to run when states in your movement class are changing.

    Is it actually just Animation you are needing to split from movement ? Sorry if this is a LOT to take in haha. Feel free to add me on skype or google chat or whatever and I'd happily talk theory all day :)
     
    Last edited: May 16, 2012
  9. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    24
    Hey again!

    Thanks for the great response! :) I believe I have an idea now how I should attempt to get this working. I might try to do as you suggested and bring this down to one fsm as the more I think about it, it should be able to operate just fine without being split up. I think I was trying to avoid duplicating the more elaborate code chunks but as long as I keep it clean/organized that shouldn't be a problem. I just bought the package so now I can get into the gritty bits and see if I run into any problems I can't work through. I really appreciate the help!
     
  10. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Honestly mate no problem, even if the product works fine for you, if I can offer any kind of advice or help in any way with your project feel free to gimmie a holler if you get stuck and I'll try my best :)

    Good luck !
     
  11. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Working on a wee update today, stay tuned today/tomorrow for it !
     
  12. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    That's a small update been made and you can see what the changes are by having a look at the ReadMe file posted in this threads main post at the PDF linked.

    You'll see the changes at the bottom of the file and a new little chapter called "The Reason Method"

    cheers !
     
  13. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    24
    Just thought I'd stop in and say I've been using this quite successfully for a few weeks. It makes organizing my enemy AI SOOO much easier. Keep up the great work :D
     
  14. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    thanks very much mate :) sorry been at home for a wedding last couple days so been troubling to keep up with the forum !

    Let me know if you need any help or anything !

    Thankyou

    Danny
     
  15. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Working on a little update as we speak :) glad that I havnt had any complaints yet the product seems to be going down a treat ! If you are using it could I ask you to please do a review in the app store as it would help me a lot ! thankyou
     
  16. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
  17. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    (bookmarked)
     
  18. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Waiting to see how it develops ? or just bookmarking out of interest ?
     
  19. abbc

    abbc

    Joined:
    Mar 12, 2011
    Posts:
    52
    Hi. How do I destroy a gameobject within a state? I got this error "'Destroy' does not exist in the current context".
     
  20. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Hiya buddy, could you please email me the problem and the bit of code you are using telling me whether it is in a state or in the FSM itself. I think you may need to do it from the FSM but I can explain this to you better if you email me :)

    danielgallagher.59@gmail.com

    thankyou !
     
  21. abbc

    abbc

    Joined:
    Mar 12, 2011
    Posts:
    52
    I sent you a p.m.
     
  22. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Ah right, this isnt an FSM problem, its a problem with your code :p lol, Im working just now but I will give you a wee message and try help you out when Im on my lunch break !
     
  23. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Hi Danny,

    I just created a simple FSM and put it on a creature object that I want it to control. How do I get access to the game object that the state is on?
    Code (csharp):
    1.  
    2.     public override void OnUpdate()
    3.     {        
    4.         // check to see if player is in front of creature and if he
    5.         // is change to hunt mode
    6.         if (player == null) {
    7.             player = GameObject.FindWithTag("Player");
    8.         }
    9.        
    10.         if (transform.InverseTransformPoint(player.position).z > 0) {
    11.             Debug.Log("facing target!");
    12.         } else {
    13.             Debug.Log("Not facing target!");
    14.         }
    15.  
    16.  
     
  24. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    OK. Got it. Parent.transform...

    Code (csharp):
    1.  
    2.     public override void OnUpdate()
    3.     {        
    4.         // check to see if player is in front of creature and if he
    5.         // is change to hunt mode
    6.         if (player == null) {
    7.             player = GameObject.FindWithTag("Player");
    8.         }
    9.        
    10.         if (Parent.transform.InverseTransformPoint(player.transform.position).z > 0) {
    11.             Debug.Log("facing target!");
    12.         } else {
    13.             Debug.Log("Not facing target!");
    14.         }
    15.  
    16.        
    17.         Debug.Log("Active" + player);
    18.     }
    19.  
     
  25. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    There you go :) feel free to post here or email me if you have any problems buddy !
     
  26. abbc

    abbc

    Joined:
    Mar 12, 2011
    Posts:
    52
    Problem solved. Thanks for your help Danny. :)
     
  27. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    No problem :) feel free to email me or message me anytime man, my personal emails are in the readme file !

    Good luck with whatever your working on
     
    Last edited: Jun 14, 2012
  28. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Thanks everyone for some excellent reviews !
     
  29. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Oh yea... I need to remember to rate you. I'm having a blast using your FSM with path finding. If I get a minute, I'll put up a web player showing off my little sample that shows a character following you around. You code made it very simple to do. Thanks.
     
  30. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    That's awesome man ! Glad its working out for you, if you don't mind I would love you to maybe email me a copy of that and maybe I can put it up and use it as like an example of someone using it and a wee link in the readme ! Thanks for the kind words buddy, good luck in your ventures
     
  31. sourcerer

    sourcerer

    Joined:
    Oct 8, 2008
    Posts:
    119
    Hi,
    Quick question - I read the documentation and am slighly puzzled. No constructor is called on the states, and the state variable is not being passed to AddState as a ref or out (so that could be doing the new and assigning it) which kinda has me puzzled. I would love for a statemachine that needs no bookkeeping of that kind (have it templatized myself in order to call a constructor from insie registerstate), so that alone would make the purchase worth it to me as a learning tool.
    Is there really no new() needed on the states, or is the documentation missing details in that regard?

    Thanks,
    Kaj
     
    Last edited: Jun 26, 2012
  32. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    It seems to me like you've missed an entire section of the Documentation. I would ask that you read it thoroughly. theres a section called

    "Implementing LZS Finite State Machine"

    Which tells you about your class that derives from FSMSystem which by the sounds of it you don't have ? Not sure how you would expect it to work then. This class handles all the State declaration's, assignements and the AddState(FSMState stateRef) function ... because it derives from FSMSystem.

    The documentation is complete friend and has very good reviews from novices and pro's alike

    Email me if you have any more trouble. My Email is IN the readme (please read it throroughly)

    Danny
     
    Last edited: Jun 26, 2012
  33. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Hi Danny,

    Did you get the webplayer I sent you?
     
  34. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Yeh kenlem that is fantastic, not had a good look yet as I've been total crunch at work this week :) but I'll respond properly to your mail when I do, good job man and thanks ! I'm sure it will come in handy as a good example of someone using our product :)

    How is your project coming along ?
     
  35. sourcerer

    sourcerer

    Joined:
    Oct 8, 2008
    Posts:
    119
    Hi Danny,

    No, I was reading the docs as an evaluation whether to purchase, so can't have errors in my implementation ;o)
    I read the manual well I believe, I was just curious how there's no new called on the states, nor is the state variable passed as a ref or out parameter, so I don't understand where the state gets actually initialized - someone has to call new WhatEverState() and assign it to s_WhateverState. If there's some wizardry involved to make that work then I'd buy it even to see how that is done.

    (and yes, I even evaluate something when it's that cheap!)

    Kaj
     
  36. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Well I'm sorry mate but the FSM works perfectly and has very good reviews by those who have bought it. I can't just start telling you the inner workings of it because then you're basically getting it for free :/ Sorry mate but I'm not prepared to tell anyone anything that doesn't appear in the Readme files. If you want to buy it to see how it works then I'm happy for you to buy it, know what I mean ? But trust me, nothing is missing from the Readme and if you do buy it then I would be happy to go over it with you inch by inch as I'm sure you'll see from this review ...



    Also are you not seeing this part of the Readme where the states are being passed as references to the state Machine's own "AddState()" function ...



    In the FSMSystem's awake function they get added and passed through ....

    Sorry again but I really cant justify telling you how I built this FSM just to satisfy your intrigue. It is also very cheap .... Thankyou for your interest
     
    Last edited: Jun 27, 2012
  37. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Webplayer is looking really cool btw :) I'm actually doing something similar for a platformer so I'll maybe chat to you about it ! Havn't properly looked at the code yet but I will tonight after work and give you a wee email.
     
  38. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Hey was just looking to hear if there was any new reviews from people who have used the FSM and any problems. Anything that has come directly to me recently seem's to have been fixed and taken into account fine and the last couple of user recommendations have lead to a couple of good updates as well as some nice example work being sent in :)

    So yeh, if you use this let me know how your getting on !

    Danny x
     
  39. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    This is simple and elegant. Love it.

    But I do have a question! My default states' OnEnter is either not getting fired, or fired too early. I popped a Debug.Log message in there and it doesn't appear in game. Unfortunately I can't debug it either because the project is on a network drive.
     
  40. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Hey sorry dude. I very rarely have been checking the forum as my Email, Skype and personal numbers are in the readme files. I wish you had let me know about your problem. Are you still having this problem as no one else is ?

    Can you please email me or add me to skype

    danielgallagher.59@gmail.com

    skype : danielgallagher.59

    Regards
    Danny
     
  41. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    I had a question. Reading the README, I see you recommend an Idle state. It appears you make one for each FSM. Can you not just make 1 general idle state class and re-use it for each new FSM? Likewise, can you re-use states between objects or fsms to create almost-alike objects, with slight differences?
     
  42. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Hey I am really sorry I didn't see this. It would be pretty strange to use the same idle state across different FSM's as I guess the parents would be of different types but this is something I will hopefully remedy in the future.

    Hope the state machine is working out for you.

    Thankyou please review!
     
  43. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    You could of course simply use inheritance and create one state machine that then others inherit from. I actually usually have an abstract state for all of my states on each single state machine. To collect things together like Parent etc.
     
  44. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  45. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Oh! That was very odd! Thankyou very much ZJP
     
  46. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    You're welcome ;)
     
  47. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    Have you actually tried it?
     
  48. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    No, but your product seem interessing and sooner or later, I will include a FSM in my project. BTW you forgot to update the link in your signature. :D
     
    Last edited: Nov 30, 2013
  49. Danny_HoW

    Danny_HoW

    Joined:
    May 4, 2012
    Posts:
    47
    hahaha! thanks again, jeez ... lol
     
  50. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,122
    Hey man, I make heavy use of your FSM. I had written something very similar myself (FSM parent, FSM states with a reference to parent, almost exactly like yours) but I use yours so I don't have to maintain anything myself.

    Anyway I just wanted to drop by and let you know that you have an error in your FSMSystem class. Both of your PushState methods do the same thing. The one that expects userData should pass userData onto the state being Pushed (OnEnter(userData)). But it doesn't. It should be

    Code (csharp):
    1. _currentState.OnEnter(userData);
    not

    Code (csharp):
    1. _currentState.OnEnter();
    In your 2nd PushState method.