Force
A force-producing rule in a continuous-time agent simulation. Given an agent and the Dynamics it belongs to, return the force vector contributed by this rule at the current simulation step.
Force is fun interface so concrete instances can be created with SAM-lambda syntax — see the canonical force library in Forces.kt:
val gravity: Force<Boid> = Force { _, _, _ -> Point2D(0.0, -9.8) }Content copied to clipboard
The force receives dt in case it depends on the integration time step (rare but useful for impulse-style forces). Most forces ignore it.
Forces are summed by the Dynamics each step; integration happens outside the force, so a force shouldn't mutate any state. Read positions via dynamics.space.positionOf(other), neighbors via dynamics.space.within(pos, radius), and other agents' velocities via dynamics.velocityOf(other).