Charge Attack
A charge attack builds power while the attack button is held and strikes when it is let go. A quick tap is an ordinary attack, a longer hold hits harder up to a full charge, and the character is slower while charging. A hit that lands during the charge breaks it and staggers the character.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Charge Attack" to my game.
What it should do: A charge attack lets the player trade time and safety for power: a stronger strike for anyone willing to stand still, slowed down and open to being hit.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> ready
ready: Ready
charging: Charging
full: Fully charged
recovery: Recovering
staggered: Staggered
ready --> charging: attack pressed
charging --> full: charge fills up
charging --> recovery: button let go
full --> recovery: button let go
charging --> staggered: hit breaks charge
full --> staggered: hit breaks charge
recovery --> ready: recovery is over
staggered --> ready: stagger is over
```
Use these starting values:
- chargeTime: 1.2 s
- tapTime: 0.2 s
- baseDamage: 10
- maxMultiplier: 4 x
- recoveryTime: 0.4 s
- tapRecovery: 0.2 s
- staggerTime: 0.5 s
- moveShare: 0.4
Watch out for these common mistakes:
- Holding on after the charge is full: Tell your AI: stop counting at a full charge. Holding on adds nothing, and the character stays fully charged until the button is let go or a hit comes.
- A hit and a release in the same moment: Tell your AI: decide from how the tick began. A hit during a charge always wins, and the strike is lost.
- Holding the button through the recovery: Tell your AI: a charge only starts on a fresh press. A button that is already down when the recovery ends does nothing.
- A tap that counts as a tiny charge: Tell your AI: a hold shorter than the tap time is an ordinary attack with the short recovery.
- Charge speed that depends on the frame rate: Tell your AI: add the time each tick covers, never a count of ticks.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
A charge attack lets the player trade time and safety for power: a stronger strike for anyone willing to stand still, slowed down and open to being hit.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Ready → Charging: attack pressed
- Charging → Fully charged: charge fills up
- Charging → Recovering: button let go
- Fully charged → Recovering: button let go
- Charging → Staggered: hit breaks charge
- Fully charged → Staggered: hit breaks charge
- Recovering → Ready: recovery is over
- Staggered → Ready: stagger is over
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| chargeTime | 1.2 s | Time to a full charge. Long enough that waiting for it is a real risk, short enough that players will try it. |
| tapTime | 0.2 s | A hold shorter than this is a tap and gives an ordinary attack. It must stay below the time to a full charge. |
| baseDamage | 10 | The damage of a tap, and where the climb starts for a charged hit. |
| maxMultiplier | 4 x | How many times the plain damage a full charge deals. Four times pays for more than a second of risk without making every other attack pointless. |
| recoveryTime | 0.4 s | The wait after a charged strike before the next attack. A big hit that can be followed at once has no cost. |
| tapRecovery | 0.2 s | The wait after a tap. Shorter than after a charged strike, so ordinary attacks still feel quick. |
| staggerTime | 0.5 s | How long a hit during the charge leaves the character helpless. It is the price of being caught. |
| moveShare | 0.4 | The share of normal speed while charging. Zero stands still, one gives no slowdown. Slow enough to feel the weight, fast enough to keep aiming. |
What usually goes wrong
Holding on after the charge is full
If the damage keeps growing with the time held, a player who waits long enough one-shots everything, and the weapon stops being balanced against anything.
Fix: Tell your AI: stop counting at a full charge. Holding on adds nothing, and the character stays fully charged until the button is let go or a hit comes.
A hit and a release in the same moment
If the release is handled first, the player strikes a split second after taking a hit that should have broken the charge. If the hit is handled first but the strike still goes out, the charge was never really broken.
Fix: Tell your AI: decide from how the tick began. A hit during a charge always wins, and the strike is lost.
Holding the button through the recovery
A player who keeps the button down after a strike starts a new charge the moment the recovery ends, without ever pressing again. That makes the slow character charge all the time by accident.
Fix: Tell your AI: a charge only starts on a fresh press. A button that is already down when the recovery ends does nothing.
A tap that counts as a tiny charge
Without a tap threshold, every press has to wait through the slowdown and the long recovery, and quick attacks feel as heavy as charged ones.
Fix: Tell your AI: a hold shorter than the tap time is an ordinary attack with the short recovery.
Charge speed that depends on the frame rate
If the charge is counted in frames instead of seconds, a computer running twice as fast charges twice as fast, and the same hold gives different damage.
Fix: Tell your AI: add the time each tick covers, never a count of ticks.
How to check it works
- Your character is ready. Press the attack button and let go after 0.1 seconds: The strike does 10 damage, the plain amount.
- Your character is ready. Hold the button for 0.4 seconds and let go, then for 0.6 seconds: The first strike does 20 damage and the second 25.
- Your character is ready. Hold the button for 1.2 seconds and let go, then for 5 seconds: Both strikes do 40 damage.
- Your character is ready. Hold the attack button: The character moves at 0.4 of its normal speed while it charges, and at full speed again when it is ready.
- Your character has been charging for 0.9 seconds. An enemy hits the character: There is no strike, the charge is gone and the character is staggered for about 0.5 seconds.
- Your character has been charging for a second. The button is let go in the same moment an enemy hits: The hit wins: no strike and the character is staggered.
- Your character has just struck and the player keeps the button down. The recovery ends: The character is ready and does not charge until the button is pressed again.
- Your character is recovering from a strike or staggered by a hit. Press the attack button: Nothing happens.
- Two games run the same 0.6 second hold, one at 120 ticks a second and one at 10. The button is let go: Both strikes do the same damage.
- Your character has just struck once with a tap and once with a charge. Count the time until it can attack again: The tap is ready sooner.
- Your character is ready. An enemy hits the character: The attack is unchanged and the character is still ready.
Works well with
- Stamina System: A charge that can drain a meter makes holding on a decision. Refuse to start a charge when the meter cannot pay for it. Check the cost when the charge starts, and spend it on the strike.
- Health and Damage: The strike hands its damage to the same damage rules as any other attack. Keep the charge curve in one place.
- Knockback: A full charge can push harder than a tap. Scale the push with the charge so the heavy hit also feels heavy.
Clashes with Combo System: A chain wants quick presses, and a charge wants one long hold on the same button. Let a tap feed the chain as usual, and start a charge only when the button is still down after the tap time.
Variations: Charge Jump.
Common questions
what do i tell my ai to add a charge attack
Paste this: Add a charge attack. Holding the attack button charges for up to 1.2 seconds and letting go strikes. A hold under 0.2 seconds is an ordinary attack. Damage climbs in a straight line from 10 to 40, holding longer adds nothing, the character moves at 0.4 of its speed while charging, and a hit breaks the charge and staggers the character for half a second.
how long should a charge attack take to charge
A little over a second is a good start. Shorter and the charge is just the normal attack, longer and players stop using it because the fight is over before it is ready.
should a charge attack slow the player down
Yes, a little. Slowing to about 0.4 of normal speed makes the commitment visible and keeps the player able to aim. Standing completely still makes the charge feel punishing.
what happens if the player gets hit while charging
Here the charge is lost and the character is staggered for half a second. Without that, charging has no risk and every player charges all the time.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 15 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it