BenchGunner
BenchGunner is a gun that fires on its own, the way a player holding the trigger does: `rate` shots a second, each one a muzzle flash at the gun, a tracer down its aim and an impact where the round lands. The gun aims along its entity's forward (-Z). It holds one effect of each k…
BenchGunner
BenchGunner is a gun that fires on its own, the way a player holding the trigger does: rate shots
a second, each one a muzzle flash at the gun, a tracer down its aim and an impact where the round
lands. The gun aims along its entity's forward (-Z). It holds one effect of each kind for as long as
it exists, and a shot plays each of them again from its start.
The bench_mixed scene uses it. Its build script spawns eight guns, BenchGun1 to BenchGun8, as
children of BenchRange, each with rate = 11 and distance = 30, to stand in for eight players
holding the trigger.
The three effects are procGraph assets played through Generator components, by default
effects.combat.muzzleFlash, effects.combat.tracer and effects.combat.impact.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
rate | number | 11 | Shots per second. |
distance | number | 30 | How far down the aim the rounds land, in metres. |
muzzleFlash | assetRef (procGraph) | effects.combat.muzzleFlash | The flash at the gun on each shot. |
tracer | assetRef (procGraph) | effects.combat.tracer | The round's trail down the aim. |
impact | assetRef (procGraph) | effects.combat.impact | What a round does where it lands. |
All fields are Sync.
Lifecycle
start(): spawns one temporary child entity per effect field that names an asset, each with a Generator set to that graph andplayOn = "manual".muzzleandtracerstand at the gun's origin, and the tracer's Generator gets the parameterdistance.impactstands at{ 0, 0, -distance }in the gun's space, turned to face back up the aim toward the gun.update(dt): whilerateis above 0, it accumulatesdt * rateshots, held at most 2, and fires one shot per whole shot owed. A long frame fires at most one shot more than a short one. A shot callsseek(0)and thenplay()on each of the three Generators.onDestroy(): despawns the child effects.
Usage
local gun = entity.spawn("BenchGun1")
gun.component.add("BenchGunner", { rate = 11, distance = 30 })
Scoped to this part · feeds back into the world's score.