Constructors

  • Parameters

    • navMesh: NavMesh

      the navmesh the crowd will use for planning

    • param1: CrowdParams

      the crowd parameters

    Returns Crowd

    Example

    const crowd = new Crowd(navMesh, {
    maxAgents: 100,
    maxAgentRadius: 1,
    });

Properties

agents: {
    [idx: string]: CrowdAgent;
}

The agents in the crowd.

Type declaration

navMesh: NavMesh

The NavMesh the crowd is interacting with.

navMeshQuery: NavMeshQuery

The NavMeshQuery used to find nearest polys for commands

raw: dtCrowd

Methods

  • Adds a new agent to the crowd.

    Parameters

    Returns CrowdAgent

  • Destroys the crowd.

    Returns void

  • Returns the number of active agents in the crowd.

    Returns number

  • Gets the agent for the specified index, or null if no agent has the given index.

    Parameters

    • agentIndex: number

    Returns null | CrowdAgent

  • Returns the maximum number of agents that can be managed by the crowd.

    Returns number

  • Returns all the agents managed by the crowd.

    Returns CrowdAgent[]

  • Gets the query filter for the specified index.

    Parameters

    • filterIndex: number

      the index of the query filter to retrieve, (min 0, max 15)

    Returns QueryFilter

    the query filter

  • Removes the agent from the crowd.

    Parameters

    Returns void

  • Steps the crowd forward in time with a fixed time step.

    There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.

    Parameters

    • dt: number

      The fixed time step size to use.

    • Optional timeSinceLastCalled: number

      The time elapsed since the function was last called.

    • Optional maxSubSteps: number

      Maximum number of fixed steps to take per function call.

    Returns void

    Example: fixed time stepping

    const deltaTime = 1 / 60;
    crowd.update(deltaTime);

    Example: variable time stepping

    crowd.update(timeSinceLastUpdate);
    

    Example: fixed time stepping with interpolation

    const deltaTime = 1 / 60;
    const maxSubSteps = 10;
    crowd.update(deltaTime, timeSinceLastUpdate, maxSubSteps);

    console.log(agent.interpolatedPosition);