Make your characters fight on their own from simple button-mashing to smart attack patterns.
MUGEN AI lives inside your character's .CMD file. It tells the game which moves to use, and when. You're writing a list of decisions the smarter the list, the smarter the fighter.
When a player is not controlling a character, MUGEN takes over and runs it as a CPU opponent. The rules for what that CPU does are called the AI Artificial Intelligence.
Without AI code, a CPU character will literally do nothing. It just stands there. Your job is to write simple rules that tell it when to attack, jump, block, or throw a special move.
All the AI code lives in one place your character's .CMD file. It's a plain text file you can open in Notepad or Fighter Factory 3.
| File | What it controls |
|---|---|
| .CMD | Inputs, commands, and AI logic |
| .CNS | States, physics, damage values |
| .SFF | Sprites (images) |
| .AIR | Animations |
| .SND | Sounds |
Open your character's folder and find the .CMD file. Open it in Notepad. Scroll all the way to the bottom that's where we'll add all our AI code.
Before you write any moves, you need to tell MUGEN that everything below is AI code. You do this with a special header block.
Scroll to the very bottom of your .CMD file and add this:
Everything you write after this block is AI code. Everything before it is normal player input commands they stay exactly as they are.
[AILevel] header tells MUGEN "only use these rules when the character is CPU-controlled." Without it, your AI triggers might fire during player-controlled rounds too!
Next, you'll write a Statedef block. Every set of AI actions lives inside a Statedef. Start with state -3 this is a special "always active" state that runs no matter what the character is doing:
-3 is your best friend for AI. It keeps running even when the character is mid-attack or knocked down. Always use -3 for your AI block.
Add the [AILevel] header and the [Statedef -3] block to the bottom of your .CMD file. Save it. This is the foundation everything else builds on.
Each AI action is a State Controller that uses a ChangeState type. You tell MUGEN: "If these conditions are true, switch to this state (do this move)."
Here's the basic template for one AI action:
Let's break down what each line means:
| Line | What it means |
|---|---|
| value = 200 | Go to state 200 that's your punch, kick, fireball, etc. |
| AILevel > 0 | Only trigger as CPU never for the human player |
| Random < 200 | Random number 0–999. Less than 200 = 20% chance per tick |
| ctrl | Short for "control = 1" character isn't in the middle of another move |
All triggers on the same number (trigger1) must ALL be true for the action to fire. It's like saying "AND" between each condition.
Add one AI action to your character a basic punch or kick. Find the state number of that move in Fighter Factory 3, then write a [State -3] block for it with a Random chance between 100 and 400.
A good AI mixes different attacks normals when close, special moves at range, supers when conditions are right. The key is order put the most important rules first, because MUGEN stops reading as soon as one fires.
Here's a layered attack setup with three tiers:
| Trigger | What it checks | Example |
|---|---|---|
| p2bodydist X | Horizontal distance to opponent | < 80 = within punching range |
| p2bodydist Y | Vertical distance to opponent | < -40 = opponent is above you |
| life | Your current life points | < 200 = dangerously low |
| p2life | Opponent's current life | < 100 = they're nearly dead |
| power | Your power/super meter | >= 1000 = one bar full |
| p2statetype | Opponent's stance | = A = they're airborne |
Add a special move AI trigger above your basic punch. Give it a distance check so it only fires when the opponent is further away. Test in MUGEN does the AI start mixing moves?
A character that only attacks is easy to beat. Real AI also knows when to jump away, back off, or activate blocking. Let's add some defensive behaviour.
Making the AI jump:
Making the AI block:
Blocking in MUGEN is handled by holding the back direction while standing or crouching. You can trigger this with a VarSet controller that holds a command. A cleaner approach used by most characters is the Guard controller:
trigger1 = A + trigger1 = B means "A AND B". But trigger2 = C adds another path "OR C" that also activates if true.
Add a walk-forward rule and a jump rule to your AI. Watch your character in CPU mode does it move around more naturally now? Try lowering and raising the Random values to see how it changes behaviour.
Now that you have AI code written, it's time to load it into MUGEN and see it in action. Here's the best workflow:
| Step | What to do |
|---|---|
| 1. Save your .CMD | Make sure you've saved the file in Notepad or FF3. |
| 2. Launch MUGEN | Open MUGEN normally it reloads character files each session. |
| 3. Watch Mode | In MUGEN, go to Watch or set both P1 and P2 to CPU. This lets you observe the AI without playing. |
| 4. Debug Mode | Press Ctrl+D in a MUGEN match to see real-time debug info state numbers, variables, and triggers firing. |
| 5. Adjust Random values | If the AI attacks too much, lower the Random cap. Too passive? Raise it. |
Common problems and fixes:
AILevel in your Random calculation:trigger1 = Random < (AILevel * 50)Set your character to CPU vs CPU in MUGEN Watch mode. Can you tune your AI to win more than half its matches against a default character? Adjust the Random values until you're happy with how it plays!
Everything you need to follow along with this workshop.