Physics queries
STPhysics asks what is where in your world. It sees only your world's objects: never StageTime's own objects,
whatever the local player is holding, or trigger colliders (unless they have an
ST Hitbox).
| API | Returns |
|---|---|
STPhysics.Raycast(origin, direction, maxDistance) | The first player, ST Hitbox or solid collider a ray hits, or null (Aiming at players) |
STPhysics.TryRaycast(origin, direction, maxDistance, out STRaycastHit hit) | The same, as true or false |
STPhysics.SphereCast(origin, radius, direction, maxDistance) | The first ST Hitbox or solid collider a moving sphere touches, or null. Players aren't hit |
STPhysics.TrySphereCast(origin, radius, direction, maxDistance, out STRaycastHit hit) | The same, as true or false |
STPhysics.OverlapSphere(center, radius, GameObject[] results) | How many objects are inside a sphere; fills results, nearest first |
STPhysics.OverlapBox(center, halfExtents, rotation, GameObject[] results) | The same for a box (halfExtents is half its size) |
STPhysics.OverlapPlayers(center, radius, StageTimePlayer[] results) | How many players (you included) are within radius of center, measured to their body from feet to head; fills results, nearest first |
Each object is listed once, even when it has several colliders. The overlap functions stop when results is full,
so make the array as big as the most you care about. Reuse the same arrays rather than making new ones each time.
Limits: sphere casts up to 10 m radius, overlaps up to 100 m, distances up to 1000 m, and at most 256 results.
Larger values are clamped. There are no layer masks: give objects you want to skip no collider, or check
gameObject.name or a component in the results. Each query counts towards the work per event like a
few hundred instructions (overlaps a little more for each object they return), so a few queries a frame are fine but
a loop of hundreds stops the script.
// A scanner: what's around it, and what's straight ahead.
public TMP_Text label;
public float radius = 3f;
private GameObject[] found = new GameObject[16];
private StageTimePlayer[] nearby = new StageTimePlayer[16];
public void Scan()
{
int objects = STPhysics.OverlapSphere(transform.position, radius, found);
int players = STPhysics.OverlapPlayers(transform.position, radius, nearby);
label.text = objects + " objects, " + players + " players";
if (STPhysics.TrySphereCast(transform.position, 0.25f, transform.forward, 20f, out STRaycastHit hit))
label.text += "
Ahead: " + hit.gameObject.name;
}
Queries are local: each device answers from what it sees, and other players' positions arrive a little late. For damage or scores that everyone must agree on, decide on one device (usually the object's owner) and share the result with synced values or a network event.
See the Area scanner example.