travelTo

suspend fun <A : AgentLike> KSLProcessBuilder.travelTo(agent: A, space: ContinuousProjection<in A>, destination: Point2D, velocity: Double, stepSize: Double = Travel.Defaults.stepSize): TravelResult(source)

Move agent from its current position in space to destination at constant velocity. The traversal takes distance / velocity simulated time units; the projection is updated to interpolated intermediate positions every stepSize coordinate-units of travel so concurrent spatial queries (space.within(...), space.neighborsOf(...)) reflect the moving agent's current position at step granularity.

Pattern (discrete-step continuous motion):

inner class Vehicle : Agent("v") {
val script: KSLProcess = process(isDefaultProcess = true) {
travelTo(this@Vehicle, mySpace, destination = Point2D(50.0, 50.0), velocity = 2.0)
}
}

Granularity tradeoff: smaller stepSize gives finer-grained position updates at the cost of more events on the calendar. The parameter is in distance (coordinate units), not time, so the spatial fidelity is the same regardless of velocity — a fast vehicle and a slow vehicle using stepSize = 0.5 both update every half-unit of travel. Pick a step that matches whatever spatial resolution matters: cell size for grid-aligned movement, collision radius for obstacle checks, pedestrian shoulder width for crowd queries.

Edge cases:

  • If current == destination (already at the target) the function returns immediately with distance == 0.0.

  • If totalDistance <= stepSize, a single delay-and-move is used (no interpolation needed).

  • The final position is set exactly to destination (not the accumulated interpolation result, which could drift due to floating-point error over many steps).

Limitations (deliberate v1 scope):

  • Uninterruptible. Once started, the travel runs to completion. To support "change direction mid-travel," wrap the call site in your own logic (e.g., short travels chained together) or use the existing delay + manual moveTo pattern.

  • No collision detection. The agent passes through other agents and obstacles. For obstacle-aware navigation use GridGraph to plan a path of waypoints, then travelTo each.

  • Constant velocity. Accelerate / decelerate isn't a primitive. Compose with multiple travelTo calls at different velocities if needed.

Return

a TravelResult describing the completed motion.

Parameters

agent

the moving agent; must be a member of space's context and already placed somewhere.

space

the projection in which the motion occurs.

destination

target coordinates.

velocity

speed in coordinate-units-per-simulated-time; must be positive.

stepSize

interpolation interval in coordinate units of travel; must be positive.