desiredVelocity

fun <A : AgentLike> desiredVelocity(speed: Double, tau: Double, direction: (agent: A, dynamics: Dynamics<A>) -> Point2D): Force<A>(source)

Helbing-style desired-velocity relaxation force: F = mass * (v_desired - v_current) / tau. Pulls the agent's velocity toward direction * speed over a timescale of tau.

The direction function should return a unit vector — e.g., field.directionAt(pos) from a FlowField. If it returns a zero vector (agent at goal or in unreachable region) the force is zero.

dynamics.addForce(desiredVelocity(speed = 1.3, tau = 0.5) { agent, dyn ->
val pos = dyn.space.positionOf(agent) ?: return@desiredVelocity Point2D.ORIGIN
flow.directionAt(pos)
})