toys
The courseToys API, `require("courseToys.toys")`: spawn fun physics toys (19 kinds, 11 themed looks) along any course and hear what happens to them. `Toys.spawn(kind, opts)`, `Toys.despawn`, `Toys.clear`, `Toys.on(event, fn)` for `hit`, `bounce`, `break`, `collect`, `enter`, `exi…
toys
The courseToys API, require("courseToys.toys"): spawn fun physics toys (19 kinds, 11 themed looks) along any course and hear what happens to them. Toys.spawn(kind, opts), Toys.despawn, Toys.clear, Toys.on(event, fn) for hit, bounce, break, collect, enter, exit, boost, slowmo and surprise, Toys.setBodyGroup so a ragdoll's bodies are bounced and boosted together, Toys.setFilter, Toys.populate(slots, opts) to fill a course from generic placement slots, Toys.kinds(), Toys.themes(), Toys.stats(). Called by game code (level generators, scene entrypoints, components); every toy is local to the peer unless spawned with synced = true. See the package README for every kind's params and events.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2courseToys.toys: fun physics toys for any course, in eleven looks. local Toys = require("courseToys.toys") local h = Toys.spawn("trampoline", { pos = { 0, 0, 5 }, theme = "candy" }) Toys.on("bounce", function(ev) print(ev.kind, ev.body, ev.speed) end) Toys.setBodyGroup(function(id) return myRagdoll:bodiesOf(id) end) Every toy works with any dynamic rigid body. Bodies that belong together (a ragdoll) are named by `setBodyGroup`, so a bounce, boost or wind changes the whole group's velocity alike (no torn limbs) and every interaction is reported once per toy and group. Toys are local to this peer unless spawned with `synced = true`.
now( ) → number return simT end
juice(name: string, pos: any, scale: number?) → void
| arg | type | description |
|---|---|---|
| name | string | |
| pos | any | |
| scale | number? |
vec(v: any) → vector
| arg | type | description |
|---|---|---|
| v | any |
emit(event: string, ev: any) → void
| arg | type | description |
|---|---|---|
| event | string | |
| ev | any |
bodyOf(id: any) → string
| arg | type | description |
|---|---|---|
| id | any |
groupOf(body: string) → void
| arg | type | description |
|---|---|---|
| body | string |
massOf(id: string) → number
| arg | type | description |
|---|---|---|
| id | string |
groupVel(group: { string }) → void
| arg | type | description |
|---|---|---|
| group | { string } |
groupPos(group: { string }) → vector
| arg | type | description |
|---|---|---|
| group | { string } |
addGroupVel(group: { string }, dv: vector) → void
| arg | type | description |
|---|---|---|
| group | { string } | |
| dv | vector |
setGroupAlong(group: { string }, dir: vector, target: number) → number
Sets the group's mean velocity along `dir` (unit) to `target`, every member alike.
| arg | type | description |
|---|---|---|
| group | { string } | |
| dir | vector | |
| target | number |
topUpAlong(group: { string }, dir: vector, target: number) → void
Top every member's speed along `dir` up to at least `target` (never slows).
| arg | type | description |
|---|---|---|
| group | { string } | |
| dir | vector | |
| target | number |
yawQuat(yaw: number) → void
toy helpers
| arg | type | description |
|---|---|---|
| yaw | number |
rotQuat(yaw: number, pitch: number, roll: number) → void
| arg | type | description |
|---|---|---|
| yaw | number | |
| pitch | number | |
| roll | number |
toWorld(st: any, p: vector) → vector
local toy space -> world (toys are posed by pos + yaw + scale)
| arg | type | description |
|---|---|---|
| st | any | |
| p | vector |
dirWorld(st: any, d: vector) → vector
| arg | type | description |
|---|---|---|
| st | any | |
| d | vector |
spawnChild(st: any, parent: any, name: string, pos: vector?, rot: { number }?) → any
| arg | type | description |
|---|---|---|
| st | any | |
| parent | any | |
| name | string | |
| pos | vector? | |
| rot | { number }? |
addPiece(st: any, parent: any, name: string, pos: vector?, rot: { number }?, pieceName: string?, look: any?) → any
Draws look piece `name` under a new entity at `pos`: one Model child per material.
| arg | type | description |
|---|---|---|
| st | any | |
| parent | any | |
| name | string | |
| pos | vector? | |
| rot | { number }? | |
| pieceName | string? | |
| look | any? |
collider(st: any, parent: any, name: string, kind: string, fields: any, pos: vector?, rot: { number }?) → any
| arg | type | description |
|---|---|---|
| st | any | |
| parent | any | |
| name | string | |
| kind | string | |
| fields | any | |
| pos | vector? | |
| rot | { number }? |
once(st: any, name: string, gkey: string, cd: number) → boolean
| arg | type | description |
|---|---|---|
| st | any | |
| name | string | |
| gkey | string | |
| cd | number |
pointOf(e: any, fallback: vector) → vector
| arg | type | description |
|---|---|---|
| e | any | |
| fallback | vector |
touch(e: any) → void
Reads a contact/trigger event: answers body, group, key, or nil when it is not a dynamic body allowed to play.
| arg | type | description |
|---|---|---|
| e | any |
event(st: any, body: string, group: { string }, key: string, point: vector, speed: number?, impulse: number?, value: any?) → any
| arg | type | description |
|---|---|---|
| st | any | |
| body | string | |
| group | { string } | |
| key | string | |
| point | vector | |
| speed | number? | |
| impulse | number? | |
| value | any? |
hit(st: any, body: string, group: { string }, key: string, point: vector, e: any, value: any?) → boolean
| arg | type | description |
|---|---|---|
| st | any | |
| body | string | |
| group | { string } | |
| key | string | |
| point | vector | |
| e | any | |
| value | any? |
addAnim(fn: (number, number) → void
| arg | type | description |
|---|---|---|
| fn | (number, number |
squash(st: any, ent: any, amount: number, dur: number, axisY: boolean?) → void
| arg | type | description |
|---|---|---|
| st | any | |
| ent | any | |
| amount | number | |
| dur | number | |
| axisY | boolean? |
tintFlash(st: any, holder: any, r: number, g: number, b: number, dur: number) → void
| arg | type | description |
|---|---|---|
| st | any | |
| holder | any | |
| r | number | |
| g | number | |
| b | number | |
| dur | number |
collect(e: any) → void
| arg | type | description |
|---|---|---|
| e | any |
addDebris(id: string, life: number) → void
debris: dynamic pieces that despawn after `life`, oldest first past the cap
| arg | type | description |
|---|---|---|
| id | string | |
| life | number |
spawnDebris(st: any, look: any, pieceName: string, pos: vector, rot: { number }, vel: vector, spin: vector, half: vector, life: number, mass: number?) → void
| arg | type | description |
|---|---|---|
| st | any | |
| look | any | |
| pieceName | string | |
| pos | vector | |
| rot | { number } | |
| vel | vector | |
| spin | vector | |
| half | vector | |
| life | number | |
| mass | number? |
burstParticles(st: any, look: any, pieceName: string, at: vector, n: number, speed: number, colours: { any }?) → void
confetti and sparkles: drawn pieces that fly ballistically (no physics cost)
| arg | type | description |
|---|---|---|
| st | any | |
| look | any | |
| pieceName | string | |
| at | vector | |
| n | number | |
| speed | number | |
| colours | { any }? |
readCamera( ) → void
step(dt: number) → void
| arg | type | description |
|---|---|---|
| dt | number |
ensureHook( ) → void
zoneEnter(st: any, body: string, group: { string }, key: string) → boolean
zone helpers: count members of each group inside a trigger
| arg | type | description |
|---|---|---|
| st | any | |
| body | string | |
| group | { string } | |
| key | string |
zoneExit(st: any, body: string, key: string) → boolean
| arg | type | description |
|---|---|---|
| st | any | |
| body | string | |
| key | string |
flushExits( ) → void
watchMode( ) → void
flipped(r: any) → any
| arg | type | description |
|---|---|---|
| r | any |
dispatch(r: any) → void
| arg | type | description |
|---|---|---|
| r | any |
ensureListener( ) → void
(Re)register the one world contact listener when this session has none yet.
listen(id: string, fn: (any) → void
| arg | type | description |
|---|---|---|
| id | string | |
| fn | (any |
zoneListen(st: any, trig: any, onEnter: ((string, { string }, string, vector) → void
a trigger listener that keeps st.inside and reports enter/exit once per group
| arg | type | description |
|---|---|---|
| st | any | |
| trig | any | |
| onEnter | ((string, { string }, string, vector |
trampoline(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
jelly(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
kicker(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
shatterGlass(st: any, body: string, group: { string }, key: string, p: vector, inDir: vector, speed: number) → void
| arg | type | description |
|---|---|---|
| st | any | |
| body | string | |
| group | { string } | |
| key | string | |
| p | vector | |
| inDir | vector | |
| speed | number |
glass(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
build( ) → void
crate(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
pins(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
count( ) → number
bumper(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
fan(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
zoneStep(_: ?, dt: ?) → void
| arg | type | description |
|---|---|---|
| _ | ? | |
| dt | ? |
launchpad(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
coins(st: ?) → void
coins along a path: params.to (local end point), params.count, params.arc (height), params.points (list of local points)
| arg | type | description |
|---|---|---|
| st | ? |
bonus(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
slowmo(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
spinner(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
tick(_: ?, dt: ?) → void
| arg | type | description |
|---|---|---|
| _ | ? | |
| dt | ? |
seesaw(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
gong(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
balloons(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
tint(e: ?) → void
| arg | type | description |
|---|---|---|
| e | ? |
pickSurprise(st: any) → string
| arg | type | description |
|---|---|---|
| st | any |
pinata(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
magnet(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
zoneStep(_: ?, dt: ?) → void
| arg | type | description |
|---|---|---|
| _ | ? | |
| dt | ? |
conveyor(st: ?) → void
| arg | type | description |
|---|---|---|
| st | ? |
kinds( ) → void
Every kind of toy: a list of { id, name, description, tags }.
themes( ) → void
Every theme id the toys have a look for ("default" is the neutral toy-box look and is also accepted).
spawn(kind: string, opts: any?) → any
Spawns a toy. opts: pos {x,y,z}, yaw (radians), theme, scale, seed, parent (entity or id), synced (default false: local to this peer), params (kind-specific tuning), shadows (default true). Answers a handle { id, kind, root, theme }.
| arg | type | description |
|---|---|---|
| kind | string | |
| opts | any? |
despawn(handle: any) → void
Removes a toy and everything it spawned (its debris keeps flying until it cleans itself up).
| arg | type | description |
|---|---|---|
| handle | any |
clear( ) → void
Removes every toy, debris piece, particle and sound voice this kit made.
on(eventName: string, fn: (any) → void
Listens for an event ("hit", "bounce", "break", "collect", "enter", "exit", "boost", "slowmo", "surprise", or "*" for all). Answers a function that stops listening.
| arg | type | description |
|---|---|---|
| eventName | string | |
| fn | (any |
setBodyGroup(fn: ((string) → void
Tells the kit which bodies belong together: fn(entityId) -> list of entity ids (or nil for "on its own").
| arg | type | description |
|---|---|---|
| fn | ((string |
setFilter(fn: ((string) → void
Which bodies may set toys off: fn(entityId) -> boolean. nil lets every dynamic body play.
| arg | type | description |
|---|---|---|
| fn | ((string |
setEffects(on: boolean) → void
Turns the kit's particle effects (juiceKit vfx) on or off.
| arg | type | description |
|---|---|---|
| on | boolean |
setVolume(v: number) → void
Sets the kit's sound volume (0..1) or mutes it (0).
| arg | type | description |
|---|---|---|
| v | number |
list(kind: string?) → void
The live handles, optionally only those of one kind.
| arg | type | description |
|---|---|---|
| kind | string? |
stats( ) → any
Counts of what the kit holds now: toys, debris, particles, animations, cached looks.
warm(kinds: { string }?, themes: { string }?) → void
Pre-builds the looks of the kinds and themes given (default: all), so the first spawn of each costs nothing.
| arg | type | description |
|---|---|---|
| kinds | { string }? | |
| themes | { string }? |
defaultWeights( ) → void
A copy of the per-kind weights `populate` picks toys by (kind id -> weight; 0 = never picked by weight). Scale or zero entries and pass the table as `opts.weights`.
newPopulateState( ) → any
A fresh populate history: pass it as `opts.state` to keep several independent courses (or players) apart.
slotDist(st: any, slot: any, prevPos: vector?) → number
| arg | type | description |
|---|---|---|
| st | any | |
| slot | any | |
| prevPos | vector? |
populate(slots: { any }, opts: any?) → void
Places a varied, fair mix of toys on generic placement slots ({ pos, forward, right, width, kind = "step"|"landing"|"ramp"|"gap", dist? }). The history is kept across calls (keyed by opts.stream, or opts.state), so chunk-by-chunk calls stay varied. opts: theme, seed, density (1), spacing (metres between toys, 11), weights ({ [kind] = w }), rarity (scales the surprise kinds), depth (metres; or each slot's dist) with depthScale (1500), or difficulty (0..1, fixed), coinEvery (metres, 32), surpriseEvery (metres, 220), window (150), minKinds (5), maxRepeat (2), parent, synced, scale. Answers the handles placed.
| arg | type | description |
|---|---|---|
| slots | { any } | |
| opts | any? |
difficulty(d: number) → number
| arg | type | description |
|---|---|---|
| d | number |
recent(d: number) → void
| arg | type | description |
|---|---|---|
| d | number |
pick(skind: string, width: number, d: number, wantSurprise: boolean) → string
| arg | type | description |
|---|---|---|
| skind | string | |
| width | number | |
| d | number | |
| wantSurprise | boolean |
record(kind: string, d: number) → void
| arg | type | description |
|---|---|---|
| kind | string | |
| d | number |
resetPopulate(stream: string?) → void
Forget the populate history of one stream (or of all of them), e.g. when a run restarts.
| arg | type | description |
|---|---|---|
| stream | string? |
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.