npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

miaoda-game-behavior-cocos

v0.3.2

Published

Cocos Creator skin for miaoda-game-behavior-core: a thin @ccclass Component that backs a behaviour-tree agent with a real Node (position/facing/movement) and drives the tree from update(dt). Ready-made line-of-sight AI for enemies, guards and NPCs.

Downloads

90

Readme

miaoda-game-behavior-cocos

Use this Cocos Creator component to run miaoda-game-behavior-core trees on a node-backed AI entity. It reads the node's position and angle, asks your hooks for target and obstacle data, advances the tree in seconds, and applies steering movement to the node.

Install

pnpm add miaoda-game-behavior-cocos miaoda-game-behavior-core

cc is an optional peer dependency supplied by your Cocos project.

Minimal guard

const ai = enemy.addComponent(BehaviorComponent);
ai.setup(
  `root { selector {
    sequence { condition [CanSeeTarget] action [MoveToTarget] }
    action [Patrol]
  } }`,
  { speed: 80, sightRange: 400, fovDeg: 70 },
  {
    target: () => player.worldPosition,
    obstacles: () => visionLayer.obstacles,
  },
  { Patrol: (agent) => patrol(agent) },
);

Cocos update(dt) supplies seconds automatically. setTicking(false) pauses the tree without clearing state; reset() starts the tree from its root. The default movement writes the node's X/Y position and sets Z to 0, so use it with 2D nodes or provide a movement arrangement appropriate for your scene.

For a game-owned fixed tick, choose manual ownership in the existing final options object:

ai.setup(tree, { speed: 80 }, hooks, custom, { tickSource: 'manual' });

fixedStepper.advance(frameDeltaSeconds, ({ dt }) => {
  ai.stepSimulation(dt);
});

The default tickSource: 'host' preserves Cocos lifecycle behavior. In manual mode, Component update(dt) is inert and stepSimulation(dtSeconds) is the only simulation entry. Calling the new entry on a host-owned component throws before the runner or Node changes. setTicking remains a separate local pause. Repeated setup replaces the runner and explicitly selects the new source; invalid replacement construction leaves the active runner and its dt binding unchanged. Destruction is terminal: later setup or stepSimulation calls throw with a repair message.

When collision, a character controller, or another simulation owns position, provide applyPosition. Built-in movement then submits its next-position request only through that hook and does not also write the Node:

const hooks = {
  target: () => player.worldPosition,
  applyPosition: (next) => character.moveToward(next),
};

Return the same obstacle collection used by miaoda-game-vision2d-core or its Cocos rendering layer. For navigation, supply findPath; for collision ownership, supply applyPosition. Sight obstacles, navigation terrain, and physical collision remain explicit host concerns.

The final optional setup argument extends BehaviorRunnerOptions with tickSource; use the same object for deterministic RNG and bounded diagnostics. The adapter strips tickSource before constructing core. Read snapshots and traces through component.runner. The component does not duplicate or mutate core diagnostic state.

Public API

BehaviorComponent, BehaviorHooks, BehaviorComponentOptions, BehaviorTickSource, BehaviorRunner, State, and core behavior types are exported. Custom functions receive the agent as their first argument. The component does not instantiate targets, query physics, or implement attacks.