Files
forma-engine/docs/SCRIPT_API.json
T
2026-09-12 04:58:59 +03:00

29 lines
2.1 KiB
JSON

{
"source": "JavaScript expression returning {start(api), update(api,dt)}. No imports or TypeScript. Worker watchdog 1500ms. Imported project scripts are TRUSTED code; Worker is responsiveness isolation, not a security sandbox.",
"api": {
"state": "Persistent per-instance mutable data during one play run",
"params": "Field defaults + component.script.params",
"input": "{x,y,z,attack,pointer,aim,jump,dash,sprint,jumpPressed,dashPressed,resetPressed,yaw,pitch}; yaw=0 faces -Z in first person",
"get": "api.get(id?) -> clone of entity or null",
"entities": "api.entities() -> clones of entity states",
"position": "api.position(id?) -> local coordinates",
"move": "api.move([dx,dy,dz]); real collisions for kinematic body",
"physics": "api.physics(id?) -> {grounded,velocity:{x,y,z},contacts:[{entityId,normal:[x,y,z]}]}",
"velocity": "api.velocity({x?,y?,z?,gravityScale?}); persistent m/s, requires 3D character or any body2d; 2D uses x/y. Gravity runs at 60 Hz",
"teleport": "api.teleport([x,y,z],yaw?); clears velocity and contacts for character respawn",
"emit": "api.emit(name,data?); delivers a presentation event to runtime callbacks",
"rotate": "api.rotate(yRadians)",
"rotate2D": "api.rotate2D(zRadians)",
"impulse2D": "api.impulse2D([x,y]); applies impulse to dynamic body2d",
"collision2d": "Optional behavior hook collision2d(api,event): {entityId,otherId,started,sensor}. Runs before update.",
"patch": "api.patch(id,patch); updates state/transform/enabled. Structural mesh/collider edits take effect next Play.",
"animate": "api.animate(clipOrState,loop=true); use false for a one-shot animation",
"effect": "api.effect(\"swing\"|\"hit\",id?)",
"spawn": "api.spawn(prefabAssetId,position); behaviors start on spawned instances",
"destroy": "api.destroy(id?); disables entity+collider",
"scene": "api.scene(sceneId); starts another scene",
"log": "api.log(text)"
},
"example": "({ update(api, dt) { const n = api.get(); api.rotate(n.transform.rotation[1] + api.params.speed * dt); } })"
}