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 | |
|---|---|
muzzle | Where 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 |
projectilePool | An ST Object Pool whose copies draw the projectiles in flight. Empty = invisible projectiles, which suits fast bullets |
speed | Metres per second (1 to 200, default 30) |
gravityMultiplier | 0 = a straight line, 1 = normal gravity (default 0.25, a gentle arc) |
radius | Projectile radius for hit detection, in metres (default 0.02) |
lifetime | Seconds before a projectile that hit nothing disappears (default 3) |
cooldown | Shortest time between shots, in seconds (default 0.15) |
hitPlayers | Projectiles can hit players (head and body). Off = they pass through players |
muzzleEffect | Optional Particle System played at the muzzle for each shot, on every device |
fireAudio | Optional 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 |
canFire | True 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 | |
|---|---|
launcher | The launcher that fired |
shooter | The player who fired |
player | The player who was hit, or null |
hitbox | The ST Hitbox that was hit, or null |
part | The hitbox's part. For players: 0 = body, 1 = head |
point, normal | Where 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 | |
|---|---|
target | Whose scripts get OnProjectileHit. Empty = this GameObject. Point an NPC's head and body hitboxes at the NPC's root |
part | A 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.
Projectiles fly in Build & Test, not in the Play preview.