Skip to content

Attack

Close-up attacks with no code: a sword swing, a punch, a bite. When its Action is pressed (or, for an enemy, when its Target comes within Range), it winds up for Windup seconds, then brings out its Hitbox (a child entity with a trigger collider and a DamageOnTouch) for ActiveTime seconds, then rests for Cooldown. Each swing hurts each thing once, however long the hitbox stays on it.

The hitbox is hidden the rest of the time, and turned to face the way its owner faces: placed to the right of it in the editor, it swings left when the player faces left (and up or down in a top-down game). If the owner has an Animation with an Attack clip (or AttackUp and AttackDown in a top-down game), it plays while the attack does.

Works with: Animation (plays an Attack clip)

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • action: text = “Attack”. The input action that swings it, e.g. “Attack” (X, L, the right mouse button or the gamepad’s X). Empty for an enemy. (Names an input action.) (Field: a name.)
  • hitbox: text = “Hitbox”. The name of the child entity that does the damage while the attack is out. (Names an entity inside this one.) (Field: an entity’s name.)
  • windup: a number = 0.05. Seconds between the swing starting and the hitbox coming out: a heavy hammer’s wind-up, or an enemy’s tell. (Field: a number.)
  • activeTime: a number = 0.15. Seconds the hitbox is out. (Field: a number.)
  • cooldown: a number = 0.2. Seconds after the hitbox goes away before it can swing again. A press meanwhile swings as soon as it can. (Field: a number.)
  • lunge: a number = 0. A speed to lunge forward at as the hitbox comes out, in world units per second. 0 stands still. (Field: a number.)
  • hitStop: a number = 0.05. Freezes the game for this many seconds when a swing lands, so it hits hard. 0 for none. (Field: a number.)
  • sound: text = null. A sound played as the hitbox comes out, e.g. “Sounds/swing.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • target: text = “Player”. For an enemy with no Action: the name of what it attacks, e.g. “Player”. (Names an entity.) (Field: an entity’s name.)
  • range: a number = 1.5. For an enemy: how close its target has to be before it swings, in world units. (A distance: the Scene view draws it as a circle around the entity, with a handle to drag.) (Field: a number.)

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • isAttacking: true or false. True from the start of a swing until its hitbox goes away.
  • isHitting: true or false. True while the hitbox is out.

Scripts use it as Attack: its methods, events and values that aren’t saved with the scene.