Skip to content

Attacks, casts and game feel ​

How a blow looks and sounds, as data: the clip or clips a unit swings with, how fast they play, what it shoots, the effect as the shot leaves and where it lands, the sounds, the streak behind the swing; a look per ability for its cast; and the feel of a hit on the screen (a flash, a flinch, a pause, a shake). The simulation's timing (damagePoint, recovery, attackSpeed) is the engine's (Combat); this page is the view's half. The editor's Attack tab sets all of it with the swing playing: Attacks and casts in the editor.

Quick start ​

ts
import type { GameView } from '@v12-engine/client'

export const view: GameView = {
	units: {
		looks: {
			footman: {
				height: 1.8,
				model: { src: 'units/footman.glb', scale: 1 },
				shapes: [],
				attacks: [{ clip: ['Melee_1H_Attack_Chop', 'Melee_1H_Attack_Slice_Diagonal', 'Melee_1H_Attack_Stab'], order: 'random', crit: 'Melee_2H_Attack_Slice', sound: 'swing', hitSound: 'hit' }]
			},
			rifleman: {
				height: 1.8,
				model: { src: 'units/rifleman.glb', scale: 1 },
				shapes: [],
				attacks: [{ clip: 'Shoot', shot: { color: [1, 0.9, 0.6], size: 0.08 }, launch: { fx: 'muzzleFlash' }, from: 'handslot.r', impact: { fx: 'sparks' } }]
			}
		}
	},
	feel: { hitStop: { crit: 0.07, kill: 0.09 }, crit: { shake: 0.15 }, kill: { shake: 0.2, sound: 'killLayer' } }
}

The footman chops, slices and stabs at random, never the same twice running, and a critical strike ends in a big two-handed slice; the rifleman's shot leaves his right hand with a flash and lands in sparks. Crits and kills pause both for a few frames and shake the view a little.

Common tasks ​

Give each weapon its own look ​

UnitLook.attacks[i] matches UnitTypeDef.attacks[i]: a second weapon's clips, shot and sounds need no code. What one leaves out is the unit's own (shot, sound, hitSound); attackClip and shotFor in code decide over it.

Play several clips, and one for a crit ​

clip: ['Chop', 'Slice', 'Stab'] with order: 'turns' (the default) or 'random': never the same twice running where there are several. crit: 'BigSlice': as the blow lands critically (or a shot leaves with a critical strike), the swing goes on as that clip from its own blow.

Fit the clip to the swing, or not ​

The clip is fitted to the swing: its length and its hit mark land on the attack's damagePoint at the unit's attack speed. speed: 1.2 plays it a little faster within that; speed: 'fixed' plays it at its own pace, not fitted (the blow on the screen is then the clip's). The editor's From the clip writes damagePoint and recovery from the clip's hit mark (damagePointFromClip), so the swing and the blow agree; the simulation keeps its numbers, so games stay in step.

Play an effect or a sound at a moment of the swing ​

Mark the moment on the clip: fx:<effect> plays the game's effect on the unit, sound:<sound> a sound, as the animation reaches it. Marks are shares of the clip and move as the clip is fitted to the swing, so a mark before the hit mark lands in the windup. Place them in the Animation panel's row above the timeline. Step by step: Time an attack and its effects to the animation.

Add a launch effect, an impact, sounds ​

launch: { fx: 'muzzleFlash' } plays at the point the shot leaves from (from, a point or node of the model: handslot.r), or as the blow lands for an attack that shoots nothing. impact: { fx: 'sparks' } where it strikes; false for none. sound as the swing starts, hitSound as the blow lands (Sounds).

Shoot something ​

shot is the ShotDef: colour, size, arc, speed, a model, a trail, an effect on it as it flies, where it lands (Ability visuals: shots). A unit's shot is for all its attacks; an attack's own shot is for that one.

Change the look with a buff or an item ​

ts
attacks: [{ clip: 'Slash', whileBuff: { embers: { shot: { color: [1, 0.5, 0.2], trail: { color: [1, 0.4, 0.1] } }, impact: { fx: 'embers' }, hitSound: 'burn' } } }]

whileBuff, by the buff's id: any field (clips, shot, effects, sounds, trail) over the attack's own while the unit carries it, the shot field by field. The first buff named that it carries. Embercrown's attacks burn because its passive keeps a buff on the carrier.

Give an ability a cast look ​

ts
fx: { abilities: { looks: { holyLight: { color: [1, 0.9, 0.6], cast: { clip: 'Cast_Raise', speed: 1.1, fx: 'handGlow', at: ['handslot.r', 'handslot.l'], sound: 'chant' } } } } }

AbilityLook.cast (CastLook): the clip or clips and their order, how fast, an effect on the hands (fx at the points at), a sound as it begins. A unit's own casts[abilityId] (UnitLook.casts) says over it field by field; the model's casts and the unit's castClip decide the clip in code.

Put it in looks.json ​

The editor writes what the Attack tab sets into looks.json beside the code (LooksEntry.attacks by the attack's place, LooksEntry.casts by the ability), laid over the view's looks. As the code's takes a field out.

Tune the feel ​

ts
feel: {
	flash: { color: [1, 1, 1], time: 0.12, strength: 0.35, crit: { color: [1, 0.8, 0.45], time: 0.18, strength: 0.7 } },
	reaction: { clip: 'Hit_A', nudge: 0.12, heavy: 0.08, crits: true },
	hitStop: { crit: 0.07, kill: 0.09, heavy: 0 },
	trails: { color: [1, 1, 1], width: 0.12, seconds: 0.16, at: 'handslot.r', melee: true, near: 45, most: 16 },
	crit: { shake: 0.15, sound: 'critLayer', float: 'Crit!', who: 'all' },
	kill: { shake: 0.2, who: 'heroes' },
	on: (hit) => (hit.target.def.id === 'critter' ? false : undefined) // your own: false for no feel on this hit
}

These are the defaults. feel: false turns all of it off; each piece false turns one off. All of it is on the screen only: the simulation goes on. A player turns hit-stop down or off (Hit-stop: full, less, off) and the shake's strength in the settings.

Add a streak behind a swing ​

trail: { color, width, seconds, at, offset, alpha } on an attack's look (SwingTrailLook), over the game's feel.trails; false for none. A melee attack has the game's where it says nothing; one that shoots has none.

Reference ​

AttackLook (UnitLook.attacks[i]) ​

FieldWhat it does
clipA clip, or several to take turns
orderturns (default) or random; never the same twice running
critThe clip of a critical strike, gone on to from its own blow
speedA factor on the fitted pace, or fixed for the clip's own
shotWhat it shoots (ShotDef); the unit's when left out
launchAn effect at from as the shot leaves, or as a blow lands
fromThe point or node it shoots from
impactAn effect where it strikes; false for none
sound, hitSoundAs it swings, as it lands
trailThe streak behind the swing (SwingTrailLook); false for none
whileBuffAnother look while a buff is carried, by buff id, any field

CastLook (AbilityLook.cast, UnitLook.casts[id]) ​

FieldWhat it does
clip, order, speedAs an attack's
fxAn effect while it winds up
atThe points it plays at (handslot.r); the middle when left out
soundAs it begins

FeelLook (GameView.feel) ​

PieceTypeWhat it does
flashFlashFeelThe struck flashes: colour, time, strength; stronger on a crit
reactionReactionFeelA flinch clip while idle, a nudge away while busy, on a heavy hit (heavy: share of health) or a crit
hitStopHitStopFeelSeconds the attacker and the struck pause on a crit, a kill, a heavy hit; times the player's setting
trailsTrailsFeelThe streaks' default look, how near they are drawn, how many at most
crit, killEmphasisFeelA shake, a sound layer, a float; whose (all, heroes, mine)
on(hit: FeelHit) => boolean | voidYour hook on every hit: false for none of it

In code: attackClip, castClip, shotFor on the unit's look decide the clip and the shot per blow; damagePointFromClip(model, clip, length, speed?) is the timing the editor writes.

Tests: packages/client/tests/attackLooks.test.ts, packages/client/tests/liteAnimator.test.ts (turns, random, the crit clip, speed), packages/client/tests/liteHitFeel.test.ts, packages/client/tests/liteHitFlash.test.ts, packages/client/tests/attackLooksFile.test.ts (looks.json), packages/editor/tests/attackModel.test.ts.