Documentation
    Preparing search index...

    Class SteeringAgent

    A mutable SteeringContext with a weighted blender and a one-line integrator — the convenience wrapper plan P8-2 leaves optional.

    It exists because every real use of this module repeats the same three things: hold the agent's state, add up several behaviours with weights, and apply the result. None of that belongs inside a behaviour, and all of it is tedious to rewrite.

    const agent = new SteeringAgent({ maxSpeed: 6, maxAcceleration: 12 });
    const scratch = new Vector3();
    const steering = new Vector3();

    agent.beginSteering();
    agent.addSteering(separation(agent, neighbors, scratch), 1.5);
    agent.addSteering(alignment(agent, neighbors, scratch), 1.0);
    agent.addSteering(cohesion(agent, neighbors, scratch), 1.0);
    agent.endSteering(steering); // weighted sum, truncated to the budget
    agent.integrate(1 / 60, steering);

    The blend is a weighted sum truncated once at the end, the simplest of the combination strategies Reynolds describes. Prioritized dithering and truncated running-sum arbitration are deliberately not here: they change which behaviours are evaluated at all, which is an application policy.

    integrate is semi-implicit Euler with a speed clamp — the §38 default and the same rule MotionComponent uses (v += a·dt, clamp, x += v·dt) — so an agent driven by this class and one driven by a MotionComponent move identically. It is a convenience for standalone agents and headless tests; an agent that is a scene node should be driven by MotionSystem (§39) or a physics body instead, with position/velocity mirroring the node.

    The three vectors are owned by the agent and never replaced. Allocation happens only in the constructor.

    Implements

    Index
    maxAcceleration: number

    Acceleration budget in units per second squared.

    maxSpeed: number

    Top speed in units per second.

    position: Vector3

    World position. Owned by the agent; write into it, never replace it.

    velocity: Vector3

    World velocity in units per second. Owned by the agent.

    • Adds acceleration · weight to the running sum. acceleration is only read, so the same scratch vector can be reused for every behaviour.

      Parameters

      • acceleration: Vector3
      • weight: number = 1

      Returns this

    • Advances the agent by deltaTime seconds under acceleration, using semi-implicit Euler with a maxSpeed clamp (see the class note). Returns this agent.

      Parameters

      • deltaTime: number
      • acceleration: Vector3

      Returns this