force
The pushes an agent can feel.
force: { pressure, containment, cursorXY, gravity, turbulence, flocking, cursorSteer, wallTurn, cursorGust, cursorInView }
Import sim from shaders/std and use sim.agentForces.force.
Each is built over your layout and returns a part the matching integrator folds in list order.
For a 3D swarm (integrator.forces3d): pressure (spread out evenly), containment (stay inside the shape), cursorXY, gravity, turbulence. For a flock (integrator.steering2d): flocking, cursorSteer, wallTurn. For drifting motes (integrator.drift2d): cursorGust. For an image relief (integrator.relief): cursorInView.
Example
integrator.steering2d(simLayout, {forces: [force.flocking(simLayout, {maxAgents: 4096}), force.cursorSteer(simLayout), force.wallTurn(simLayout)], agitation: {rest: 1.5, gain: 0.45, cool: 1.3}, cruiseFloor: 0.35, wallRestitution: 0.6, name: 'boidsUpdate'})
Tip. Order matters only for readability. The forces are summed, so list them from the most important down.
Members
force.pressure— Spread a 3D swarm evenly by pushing agents away from crowded cells of a density grid.force.containment— Keep a 3D swarm inside a shape: a spring at the surface, a pull back from far away, and a drag when the shape rotates.force.cursorXY— The cursor as a magnet on a 3D swarm, pushing away (or pulling in when the force is negative).force.gravity— A constant pull on a 3D swarm in the direction ofparams.gravX, gravY.force.turbulence— A per-agent jitter that keeps a 3D swarm alive, scaled byparams.agitation.force.flocking— Separation, alignment and cohesion for a flock, with live weights and radii.force.cursorSteer— The cursor on a flock: attract, scatter like a predator, or nothing.force.wallTurn— A soft turn back toward the canvas near an edge, so a flock arcs instead of bouncing.force.cursorGust— A puff from the cursor on drifting motes, zero while the force slider sits at 0.force.cursorInView— The cursor on an image relief, applied where each particle appears on screen.
See also
integrator— The update step of an agent simulation: one per kind of agent.torque— The turns an agent that spins in place can feel, forintegrator.orientation2d.shapeField— The signed-distance function of the shape a swarm lives in, forforce.containment.agentFrame