# Movement in Continuous Space

AnyLogic continuous space support includes ability to set and retrieve the current agent location, to move the agent with the specified speed from one location to another, to execute action upon arrival, and to animate the (static or moving) agent at its location. Part of continuous space functionality does not even require the agents to belong to an explicitly specified environment - without the environment the default space type assumed is continuous space.

### Calling agent movement functions

Agent type has a rich API for moving in continuous space. First, there are functions to obtain the current location and distance (these functions work when the agent is moving as well). Then there is a set of functions for relocating the agent and getting the related information. The agents can move with some travel time or jump instantly to the target location.

Sometimes calling one or another function may result in triggering the code of an agent action On arrival to target location

First, you might need to get information about the agent position and define its target location coordinates.

Getting agent's current coordinates

double getX() - returns the current (up-to-date) X-coordinate of the agent.

double getY() - returns the current Y-coordinate of the agent.

double getZ() - returns the current Z-coordinate of the agent in continuous 3D space.

Getting the target coordinates

double getTargetX() - returns the X-coordinate of the target location if the agent is moving, and its current X otherwise.

double getTargetY() - returns the Y-coordinate of the target location if the agent is moving, and its current Y otherwise.

double getTargetZ() - returns the Z-coordinate of the target location if the agent is moving, otherwise current Z-coordinate.

Calculating distance

double distanceTo(Agent other) - returns the distance to a given other agent.

double distanceTo(double x, double y) - calculates the distance from this agent to a given point (x, y) in space.

double distanceTo(double x, double y, double z) - calculates the distance from this agent to a given point (x, y, z) in continuous 3D space.

#### Agent movement

The movement goes at the given speed (which however can be changed dynamically). The agent will execute On arrival to target location action when (and if) it reaches the target location.

The following methods make agents move to the given target location along the shortest straight line, where x, y, z are the target coordinates in 2D or 3D continuous space:

moveTo(double x, double y)

moveTo(double x, double y, double z)

You can define movement to the specific model element using its name as the target. There are three main types of such objects:

moveTo (Agent agent) - starts movement to the given agent. Code defined in the agent's On arrival property is executed when this agent reaches the destination.

moveTo(Node node) - starts movement to the given node.
Parameter: node -  the node which may, or may not, be part of network

moveTo(Attractor attractor) - starts movement to the given attractor inside a node.
Parameter: attractor - the attractor

moveToNearestAgent (Agent agents) - starts movement to the nearest agent from the given population of agents. Stops any current movement.
Parameter: agents - the population of agents

#### Instant jumping

These functions instantly place the agent to a given location or node. They terminate any movement and do not call On arrival to target location code.

You are familiar with the parameters:

jumpTo(double x, double y)

jumpTo(double x, double y, double z)

jumpTo(Node node)

#### Defining time of movement

The following methods change the speed of the agent in order to reach target in tripTime model time units. You know all the parameters, except for tripTime - the time of the movement.

moveToInTime(Agent agent, double tripTime)

moveToInTime(double x, double y, double tripTime)

moveToInTime(double x, double y, double z, double tripTime)

moveToInTime(Node node, double tripTime)

moveToInTime(Attractor attractor, double tripTime)

moveToNearestAgent(Agent agents, double tripTime)

Each moveToInTime() function has another notation with one more argument: units. Use this notation when you want to specify the trip time not in the model time units, but in some other time units. Pass one of time unit constants (e.g. MINUTE, HOUR, DAY) as the units argument value. Let us say, that model time units are seconds, but the trip time is 2 days, so it is easier for you to write truck.moveToInTime(city, 2, DAY) and the agent truck will start its movement to the agent city. It will take two days for the truck to reach city.

moveToInTime(Agent agent, double tripTime, TimeUnits units)

moveToInTime(double x, double y, double tripTime, TimeUnits units)

moveToInTime(double x, double y, double z, double tripTime, TimeUnits units)

moveToInTime(Node node, double tripTime, TimeUnits units)

moveToInTime(Attractor attractor, double tripTime, TimeUnits units)

moveToNearestAgent(Agent agents, double tripTime, TimeUnits units)

boolean isMoving() - tests if the agent is currently moving.

double timeToArrival() - if the agent is moving, returns the remaining time to arrival assuming the speed will not change. If the agent is not moving, returns 0. The function returns time in model time units.

double timeToArrival(TimeUnits units) - if the agent is moving, returns the remaining time to arrival assuming the speed will not change. If the agent is not moving, returns 0. The function returns time in given time units. You specify time units with the function argument units, passing one of time unit constants (e.g., MINUTE, HOUR) as the argument value.

stop() - stops the agent (if it was moving) and leaves it at the current location. The agent action On arrival to target location is not executed.

### Defining movement with flowchart objects

Another way to move agents is to define corresponding parameters in the flowchart objects' properties. Most frequently you build flowcharts using Process Modeling Library

The Process Modeling Library block, which is designed specifically to simulate agent movement, is called MoveTo. In its properties, you can choose, whether you want the agent to move or to jump to the target destination (option Agent: moves to / is placed (jumps) to). The Destination property has a lot of useful options, which apply both for moving and jumping:

If you select Network / GIS node as Destination, you can simply select it from the Node drop-down list below.

You can also set custom speed for a moving agent, or a trip time, as if you were using moveToInTime() functions.