Log inGet started
World

Procgen Effects Showcase

Branchmain
Branchesmain
Commit99ff90d12c

README.md

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

FieldTypeDefaultDescription
effectassetRef (procGraph)effects.combat.muzzleFlashThe effect fired on each press.
inputMapassetRef (inputMap)weapon.weaponThe controls live while this peer's player owns the body. fire is the one that shoots.
aheadnumber0.8How far in front of the body, along the aim, the effect fires from, in metres.
heightnumber1.4How far above the body's origin the effect fires from, in metres.
sidenumber0.35How far to the right of the body, across the aim, the effect fires from, in metres: where a gun in the right hand is.
ratenumber11Shots 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 at at (a world position { x, y, z }), pointing along dir (a world direction { x, y, z }), on this peer. It is declared in syncedFunctions, so a call plays the shot on every peer. It makes the muzzle effect on first use (a temporary child entity named muzzle with a Generator for effect, playOn = "manual"), and makes it again when effect names another asset. It moves the muzzle to at, turns its forward (-Z) onto dir, 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 activates inputMap and listens to its fire control: 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 and rate is above 0, it accumulates dt * rate shots (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.