Attack
namespace Griff.Scenes;
public sealed class Attack : ComponentClose-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.
Properties
Section titled “Properties”Action
Section titled “Action”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.
ActiveTime
Section titled “ActiveTime”public float ActiveTime { get; set; }Seconds the hitbox is out.
Cooldown
Section titled “Cooldown”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.
HitStop
Section titled “HitStop”public float HitStop { get; set; }Freezes the game for this many seconds when a swing lands, so it hits hard. 0 for none.
Hitbox
Section titled “Hitbox”public string? Hitbox { get; set; }The name of the child entity that does the damage while the attack is out.
IsAttacking
Section titled “IsAttacking”public bool IsAttacking { get; }True from the start of a swing until its hitbox goes away.
IsHitting
Section titled “IsHitting”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”.
Target
Section titled “Target”public string? Target { get; set; }For an enemy with no Action: the name of what it attacks, e.g. “Player”.
Windup
Section titled “Windup”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.
Methods
Section titled “Methods”public bool Swing()Swings now if it isn’t already swinging or cooling down; returns whether it did. For scripts and cutscenes.
Events
Section titled “Events”public event Action<Entity>? HitRaised when a swing lands on something, with what it hit.
public event Action? SwungRaised as the hitbox comes out.