Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-physics

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Choose builtin, cannon or Box2D physics; wire rigid bodies, colliders and raycasts. Use for missing gravity, trigger filters, backend limits or material error 9642.

  • 9 files
  • 37.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-physics

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesquick-start.md

≈863 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-physics skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Environment: the HTML examples using /build/ require the AIR development server and an existing bundle. In npm applications use the installed package name and the application's own bundler/server; resolve docs and declarations from that package. Do not copy repository URLs into a consumer app. Browser behavior is verified only for explicitly tested snippets and candidates.

Quick Start

<canvas id="GameCanvas"></canvas>
<script type="importmap">
  { "imports": { "cocosair": "/build/cocosair.module.js" } }
</script>
<script type="module">
import { createAirApp, Scene, Node, Camera, DirectionalLight, Component, Color, Vec3,
         BoxCollider, RigidBody, ERigidBodyType, PhysicsSystem, geometry } from 'cocosair';

// 'builtin' is also the default when physics is omitted; write it so the choice is visible.
// For gravity, falling and stacking use { physics: 'cannon' } instead - builtin has no integrator.
const app = await createAirApp({ canvas: '#GameCanvas', physics: 'builtin' });
const scene = new Scene('physics-demo');
const camNode = new Node('Main Camera'); scene.addChild(camNode); camNode.setPosition(new Vec3(0, 4, 10));
const camera = camNode.addComponent(Camera);
camera.projection = Camera.ProjectionType.PERSPECTIVE; camera.fov = 45; camera.near = 0.1; camera.far = 100;
camera.clearFlags = Camera.ClearFlag.SOLID_COLOR; camera.clearColor = new Color(24, 30, 44, 255);
const lightNode = new Node('Main Light'); scene.addChild(lightNode); lightNode.setRotationFromEuler(-45, -30, 0);
lightNode.addComponent(DirectionalLight).illuminance = 50000;

const ground = new Node('Ground'); scene.addChild(ground);
const groundBody = ground.addComponent(RigidBody); groundBody.type = ERigidBodyType.STATIC;
const groundCollider = ground.addComponent(BoxCollider); groundCollider.size = new Vec3(12, 0.2, 12);

const sensorNode = new Node('Sensor'); scene.addChild(sensorNode); sensorNode.setPosition(0, 1, -3);
const sensor = sensorNode.addComponent(BoxCollider); sensor.isTrigger = true;
let triggerLog = 'none';
sensor.on('onTriggerEnter', () => { triggerLog = 'enter'; });
sensor.on('onTriggerExit', () => { triggerLog = 'exit'; });

// builtin never moves a node by itself: drive the transform yourself, sync is lazy.
const crate = new Node('Crate'); scene.addChild(crate); crate.setPosition(-2, 0.8, 2);
const crateBody = crate.addComponent(RigidBody); crateBody.type = ERigidBodyType.KINEMATIC;
crate.addComponent(BoxCollider).size = new Vec3(1.5, 1.5, 1.5);

class Driver extends Component {
    constructor () { super(); this.t = 0; }
    update (dt) {
        this.t += dt;
        crate.setPosition(-2, 0.8, 2 - Math.min(this.t * 2, 6));
        if (this.t > 1 && this.t < 1 + dt) {
            const ray = new geometry.Ray(0, 0.8, 4, 0, 0, -1);   // origin + direction, not a target point
            const hit = PhysicsSystem.instance.raycastClosest(ray);   // returns boolean
            console.log('closest hit:', hit, triggerLog);   // read PhysicsSystem.instance.raycastClosestResult
        }
    }
}
crate.addComponent(Driver);
app.run(scene);   // async render loop; PhysicsSystem steps inside it

function teardown () { PhysicsSystem.instance.enabled = false; scene.destroy(); }
</script>

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "dynamic bodies do not fall or stack",
  "triggers stop firing after changing collision groups",
  "choose builtin or cannon before startup",
  "query 2D bodies with raycasts or overlap tests",
  "physics material error 9642 appears"
]
owns
[
  "builtin-physics",
  "cannon",
  "box2d",
  "collision-filter",
  "rigid-body",
  "physics-queries"
]
not_for
[
  "camera pixel-to-ray conversion -> cocosair-camera",
  "node hierarchy and transforms -> cocosair-scene-graph",
  "non-physics startup errors -> cocosair-application"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "选择 builtin 或 cannon,并区分碰撞检测、运动积分和二维 Box2D 的能力。用于刚体、触发器、射线查询或物理后端问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-physics