Skip to main content
Version: 0.4.1

ST Projectile Launcher and ST Hitbox

An ST Projectile Launcher fires projectiles (paintballs, bullets, darts, snowballs) and tells your scripts what they hit. Add it with Add Component → StageTime → ST Projectile Launcher, usually beside an ST Pickup. StageTime flies the projectiles itself, so a burst of fire costs your script nothing per frame, and it handles the networking: every player sees every shot, and every player's device gets the same hit.

Field
muzzleWhere projectiles start and which way they go (its blue Z axis). Empty = the launcher's transform. On desktop a held launcher aims at the centre of the screen instead
projectilePoolAn ST Object Pool whose copies draw the projectiles in flight. Empty = invisible projectiles, which suits fast bullets
speedMetres per second (1 to 200, default 30)
gravityMultiplier0 = a straight line, 1 = normal gravity (default 0.25, a gentle arc)
radiusProjectile radius for hit detection, in metres (default 0.02)
lifetimeSeconds before a projectile that hit nothing disappears (default 3)
cooldownShortest time between shots, in seconds (default 0.15)
hitPlayersProjectiles can hit players (head and body). Off = they pass through players
muzzleEffectOptional Particle System played at the muzzle for each shot, on every device
fireAudioOptional Audio Source that plays its clip for each shot, on every device
Member
Fire()Fires one projectile from the muzzle, with the local player as the shooter. Returns false while cooling down or with 16 projectiles in flight
FireFrom(position, direction)Fires from any point in any direction (world space), for turrets and scripted shots. Same rules
canFireTrue when Fire would fire now

Call Fire on one device: usually the holder's, from OnPickupUseDown. The shooter's device works out what the projectile hits and tells everyone else, so a hit is never counted twice or missed.

public class Blaster : StageTimeBehaviour
{
public STProjectileLauncher launcher;

public override void OnPickupUseDown() => launcher.Fire();
}

OnProjectileHit​

When a projectile hits a player, an ST Hitbox or anything else with a collider in your world, the scripts on the launcher's GameObject get OnProjectileHit(STProjectileHit hit) on every player's device, with the same details. If it hit an ST Hitbox, the scripts on the hitbox's target get it too.

STProjectileHit
launcherThe launcher that fired
shooterThe player who fired
playerThe player who was hit, or null
hitboxThe ST Hitbox that was hit, or null
partThe hitbox's part. For players: 0 = body, 1 = head
point, normalWhere it hit and the surface normal there (world space)

Every device runs the event, so it is the place for things everyone should see: a splat, a sound, a target falling. Change synced values (scores) on one device only, for example on the owner of your game script, as in the Paintball Range example:

public override void OnProjectileHit(STProjectileHit hit)
{
splats.Spawn(hit.point + hit.normal * 0.004f, Quaternion.LookRotation(-hit.normal));
if (hit.player != null && Networking.IsOwner(game.gameObject))
game.AddPoint(hit.shooter);
}

Projectiles pass through trigger colliders (unless they have an ST Hitbox), through the launcher's own object and through the shooter. They hit players only while at least one launcher with hitPlayers is in the world.

ST Hitbox​

Marks a collider as something projectiles report: a target, an NPC's head or body, a breakable prop. Add it with Add Component → StageTime → ST Hitbox on a GameObject with a collider (a trigger collider works too).

Field
targetWhose scripts get OnProjectileHit. Empty = this GameObject. Point an NPC's head and body hitboxes at the NPC's root
partA number of your choice that hits report as part, for example 0 = body, 1 = head

Turn a hitbox off by disabling its collider (a knocked-down target, for example). GetTarget() returns the target, or the hitbox's own GameObject.

Local preview

Projectiles fly in Build & Test, not in the Play preview.