Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Control Logic in games

A topic by logicandchaos created 23 days ago Views: 199 Replies: 6
Viewing posts 1 to 3

What do you use for control logic? Is it integrated in your scripts? Do you use state machines, behaviour trees, animation triggers?

I've used many different things over the years and they can get really messy and complicated.

Then one day I was watching GDC videos and I seen one on Valve's bark system they use for character vocalizations and it was so simple and can be expressed as a simple spread sheet.

I quickly implemented my own version and using it in various ways realizing it could be used for so much more than barks, it could drive any reactive gameplay system.

After using it for many projects I decided to build it out as a full tool for Unity! I optimized it to run in unity and completely integrated it into the editor! I even created wizards for generating code, making it usable by designers not just programmers.

Fuzzy Brain is a rule-based decision system, where you completely separate the control logic out, making cleaner code and reduced complexity. You define Acts and the Conditions under which they will be called, Fuzzy Brain takes care of the rest.

Check it out on the Unity Asset Store!

https://assetstore.unity.com/packages/tools/behavior-ai/fuzzy-brain-349538

(+1)

To answer your question, I code the control logic of my games in C. I choose the data structure that best fit the situation and in most cases I use arrays for fast access.

Nice, C was my 1st language.

What I mean is more the structures and patterns used for behaviour and decision-making, like state machines, decision Tree, utility function, behaviour trees, just ifs/conditionals. I created a new system in Fuzzy Brain!

With Fuzzy Brain I separate all that logic out of the scripts, leaving just the implementation logic, the functions that perform the actions, then Fuzzy Brain calls those functions when the right conditions are met.

I define conditions, like is heallth<10 or if enemy distance < 20 and I put the conditions I want in a list in the Act, then when all the conditions are met the Act calls the function.

It's a great way to separate code by separating decision logic from implementation and makes the code clean, modular, reusable, and easier to maintain.

(+1)

I always build the logic with if/else and switch but the number of enemy types I have is usually small. Your system has a lot of potential when enemy types become numerous.

Oh for sure! You can make different behaviours for different enemy types, they are stored in ActLists which can be shared among Actors. And you can edit the behaviours without writing anymore code.

(+1)

The barks-to-general-reactive-layer leap is a good one 🎮 — barks are the one place where “conditions → pick an act” is already forced to be data, because designers have to author hundreds of them and nobody is writing that as if/else.

For what it’s worth, the AI in my own game (a browser bomber arena, bots fighting continuously) ended up as a scored candidate list rather than a state machine or a behaviour tree: each tick, generate the legal moves, hard-gate the ones that are suicide, score what is left, take the best. Conditions are data in much the same way yours are.

The thing that bit me, and I think it bites any condition-driven system, is that a condition is rarely read by only one act. I have a “can I survive this?” predicate. Some maps have teleport pads, and a body in transit cannot be touched by anything for four seconds, so it looked obviously correct to let “I can reach a pad” satisfy that predicate. Pure upside. One word to change.

Self-kills went UP nine points. Because that predicate is not only the escape check — it is also what licenses placing the bomb in the first place. Making it easier to satisfy quietly approved exactly the bombs whose escape was the longest walk on the board.

Two things I would hand anyone building this kind of layer:

  • Ordering is not a tiebreak. “Walk to a haven” and “dive into a pad” both satisfy survive, but a pad costs four seconds of the round and hands the exit to a draw, so it is asked second, always. In a flat rule list that ordering is invisible, and what you get is a bot that gambles when it did not have to.
  • When a number is load-bearing, put it in the code with a test asserting it, because the tempting edit is one word long.

Curious where Fuzzy Brain puts precedence when two Acts have all their Conditions met at once — is it list order in the ActList, or is there a score underneath?

Thanks for the input, I use a greedy algorithm so the 1st match is the one that runs, but I have it ordered so that more specific Acts are checked 1st, if certain behaviours are always running where other Acts don't even get evaluated, then adding in more conditions can solve it. There is a bit of a learning curve, but overall it's a very simple system to use.