I’m working on a remake of Slay the Spire to learn game dev and Unity, and I’ve hit a roadblock with enemy AI. Some enemies are pretty easy to design like the Corrupt Heart (Buff-attack-attack cycle) or Cultist (buffs on turn 1 then always attacks) since their attack patterns are entirely scripted. But when I get to more complex enemies like the Jaw Worm, I get confused.
For reference, the Jaw Worm’s AI is as follows:
Always starts with Chomp.
Afterwards, has a 45% chance of using Bellow, 30% chance of using Thrash, and 25% chance of using Chomp.
Cannot use Bellow twice in a row, cannot use Thrash 3 times in a row, and cannot use Chomp twice in a row.
I’ve got the percent chance working by creating a random double (0.0 – 1.0) and comparing it to the percent values, and I have a system set up to calculate how many times a move has been used in a row. However, determining which move to use based on these values is still proving difficult.
For example, let’s say the random double creates a value equal to 0.3, meaning the Jaw Worm’s next move should be Bellow. But then, what if Bellow was the move used last turn? Which move should then be selected? Because Bellow was the last move used, neither Thrash or Chomp were used and therefore their additional logic cannot be used to narrow down the choice. So which move should it be?
Currently, I’ve got a giant if-statement that handles all the options, but it has to choose one of the other moves first and that doesn’t seem right to me. For those of you who’ve worked with similar enemy AI patterns, what have you done to tackle issues or systems like this? Should I be calculating the percent chance first and then checking for a move streak (my current approach), or should I check the move streak and then calculate a percent chance?
submitted by /u/jaquarman
[link] [comments]
Unity2D – Develop 2D games using Unity