Learn what AI is in MUGEN and where the AI code lives inside your character files.
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 |
Add the [AILevel] header and [Statedef -3] block to the bottom of your .CMD file.
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.Write your first AI trigger block that makes the CPU throw a punch when the opponent is close.
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:
| 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.
Build a layered attack priority system: supers first, specials second, normals last.
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.
| 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 movement and blocking rules so the AI can dodge, approach, and defend.
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 and walk
Making the AI block
trigger1 = A + trigger1 = B means "A AND B". But trigger2 = C adds another path "OR C".Test your AI in Watch mode and tune the Random values until your character fights well.
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). At difficulty 1 this is 50, at difficulty 8 it's 400.