FlashFire
FlashFire fires an effect from in front of the player, away from the camera the player looks through, while the player presses or holds `fire`. It sits on the player's body: the peer that owns the body reads the control and aims the shot, and every peer plays it, because `shoot`…
FlashFire
FlashFire fires an effect from in front of the player, away from the camera the player looks
through, while the player presses or holds fire. It sits on the player's body: the peer that owns
the body reads the control and aims the shot, and every peer plays it, because shoot is a synced
function.
The gun has one effect of its own, standing at its muzzle as a child of the body. A shot moves it to where the muzzle is, turns it down the aim and plays it again from its start, so a body firing any number of shots holds one effect, and each body in the world holds its own.
The main scene uses it on the body entity of DefaultSocialPlayer, the PlayerPrototype under
PlayerSetups, with effect set to effects.combat.muzzleFlash and inputMap set to
weapon.weapon. It aims with the Camera of the CameraRig entity whose follow is this body.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
effect | assetRef (procGraph) | effects.combat.muzzleFlash | The effect fired on each press. |
inputMap | assetRef (inputMap) | weapon.weapon | The controls live while this peer's player owns the body. fire is the one that shoots. |
ahead | number | 0.8 | How far in front of the body, along the aim, the effect fires from, in metres. |
height | number | 1.4 | How far above the body's origin the effect fires from, in metres. |
side | number | 0.35 | How far to the right of the body, across the aim, the effect fires from, in metres: where a gun in the right hand is. |
rate | number | 11 | Shots per second while fire is held down. A press fires at once; holding it keeps firing at this rate. |
All fields are Sync.
Methods
:shoot(at, dir): plays the effect atat(a world position{ x, y, z }), pointing alongdir(a world direction{ x, y, z }), on this peer. It is declared insyncedFunctions, so a call plays the shot on every peer. It makes the muzzle effect on first use (a temporary child entity namedmuzzlewith a Generator foreffect,playOn = "manual"), and makes it again wheneffectnames another asset. It moves the muzzle toat, turns its forward (-Z) ontodir, seeks the Generator to the first frame of its playback and plays it.
Lifecycle
update(dt): on the peer that owns the body, while the engine runs unpaused, it activatesinputMapand listens to itsfirecontrol: a press fires one shot at once and holds the trigger, a release lets go. Elsewhere, and while paused, it deactivates the map and lets go of the trigger. While the trigger is held andrateis above 0, it accumulatesdt * rateshots (held at most 2, so a hitch adds at most one extra shot) and fires one per whole shot owed.onDestroy(): deactivates the input map and despawns the muzzle effect.
A shot finds the aim camera and places the effect at the body's position plus ahead along the
camera's forward, side along its right and height up, then calls shoot with that position and
the camera's forward.
If the input map raises an error on activation or deactivation, FlashFire reports it with warn.
Scoped to this part · feeds back into the world's score.