Skip to content

Attack

namespace Griff.Scenes;
public sealed class Attack : Component

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.

This is a component: its saved properties are on its component page.

public string? Action { get; set; }

The input action that swings it, e.g. “Attack” (X, L, the right mouse button or the gamepad’s X). Empty for an enemy.

public float ActiveTime { get; set; }

Seconds the hitbox is out.

public float Cooldown { get; set; }

Seconds after the hitbox goes away before it can swing again. A press meanwhile swings as soon as it can.

public float HitStop { get; set; }

Freezes the game for this many seconds when a swing lands, so it hits hard. 0 for none.

public string? Hitbox { get; set; }

The name of the child entity that does the damage while the attack is out.

public bool IsAttacking { get; }

True from the start of a swing until its hitbox goes away.

public bool IsHitting { get; }

True while the hitbox is out.

public float Lunge { get; set; }

A speed to lunge forward at as the hitbox comes out, in world units per second. 0 stands still.

public float Range { get; set; }

For an enemy: how close its target has to be before it swings, in world units.

public string? Sound { get; set; }

A sound played as the hitbox comes out, e.g. “Sounds/swing.wav”.

public string? Target { get; set; }

For an enemy with no Action: the name of what it attacks, e.g. “Player”.

public float Windup { get; set; }

Seconds between the swing starting and the hitbox coming out: a heavy hammer’s wind-up, or an enemy’s tell.

public bool Swing()

Swings now if it isn’t already swinging or cooling down; returns whether it did. For scripts and cutscenes.

public event Action<Entity>? Hit

Raised when a swing lands on something, with what it hit.

public event Action? Swung

Raised as the hitbox comes out.