After google one hour, I am still not sure what to do with my tile based slg game AI.
The high score AI package in asset store is very expensive, I would prefer to program myself.
I don’t think a long list of “switch() case” is a good approach. State machine have a serious bug that remove all its behavior script. So if I use state machine, i cannot add anything on the behavior. I am not sure if it will create progam problem issue later.
You’d have to have a pretty difficult AI to not be able to use a state machine. They have a lot of advantages. The character can only be in one state at a time, so they are pretty easy to debug, and they are fairly expandable. You can use Mecanim as a state machine, but it’s probably better to write your own. The old switch case is probably a good way to start, although there are plenty of examples on youtube. You can always make sub-states if it gets overwhelming. If you use a switch case, you should use enums rather than numbers so your code is easier to read. Otherwise a class based system is a little bit of a step up with an interface. Most of it is using good coding principles. Don’t put all the working code in the main branches so you can get an overall view of what you are doing. It’s like looking at some people’s Update code. Put some of that in separate methods so it’s readable and easier to debug.
No where is it said that switch statements are required for State Machines. Instead of enums you can use classes to represent unique states. if you are going to tackle a deep topic such as AI for the first time, you shouldn’t worry so much about getting it right the first time. Good AI systems take time to develop well and the best course for a beginner is an iterative approach.
If you’re looking for some excellent resources for researching AI (as it pertains to games) the best source that I have come across is the GDC Vaults, there’s a wealth of information available there. You can go there and see what types of AI systems there are and see which one you would like to try developing for your game.
State Machines also have their own limitations, granted they are the easiest to set up and are often the most performant of the AI Systems (just because of their relative simplicity), they often make their AI avatars seem… one dimensional. state machines are at their best when the end-user expects the behavior of a system to act in a highly predicable and consistent manner, such as a Vending machine always providing their product when you exchange currency, or an elevator always transporting it occupants to a selected floor while having its doors closed during motion or a turn-based game always giving two opposing players alternating turns to act.
Creating a complex AI in a State Machine is possible, but it’s usually far more effort than worth to get right. while other options can create that same complex behavior with less effort.
Behavior Trees are a great choice, it allows you to make a tree of questions to reach the leaf nodes holding the actual behavior. depending on how those questions get answered determines which behavior the Avatar will perform. Behavior are relatively simple to set up and allows you to make some Smart AI. Its still technically a state machine but the entire structure and flow of state is very different from the usual state machine.
Utility systems are also a good option if you want the avatar constantly changing its priorities. in such systems the avatar will also have a tree of nodes where each node would have a list of choices with the behavior on the leaves. The decision it makes depends which choice has the most concern. each choice can generate more concern or less depending on whats happening in the game around said avatar. for example a mob might choose to fight the player cause its “Hate” choice is generating the most concern, but then when its health gets too low its “Fear” choice will have a much higher concern than “Hate” forcing the mob to flee. Utility can make for intelligent AI but will require a ton of tweaking and testing.