AnyLogic
Expand
Font size

Agent animation rotation

AnyLogic supports rotation of the agent's animation shape while the agent is moving and provides API that you can use to control the rotation of the shape.

If you need to set the rotation of the agent's animation shape while the agent stays at some specific point, then you can use an attractor.

Rotating the agent's animation according to the movement direction

Most often the animation shape of the agent should rotate during the movement of the agent according to the direction of its movement. The agent type has the corresponding option Rotate animation towards movement in the Dimensions and movement properties section. When this option is selected, the agent's animation shape automatically rotates when moving. Since this behavior is required in most models, this option is selected by default.

Below you can see how the tanker movement is animated with autorotation turned on and off.

Autorotation is on Autorotation is off

Turning off the autorotation

Well, when might you want to turn off autorotation? For example, if your model does not have 3D animation, and you use icons as agent animation shapes. Say, if the agent will move along winding routes on a GIS map, if the autorotation is turned on, the agent's animation shape will constantly twitch, creating an undesirable visual effect. Another example: if the animation shape has text labels and you don't want them to be displayed upside down when the shape is rotated.

Below, you can see how the animation of the agent's movement looks with the autorotation option turned on and off. Here, a car (represented by a red icon) and a train (a blue icon) are moving on the map. The autorotation option is enabled for the car, but not for the train. You can decide on your own which option is preferable for you.

Vertical rotation of the agent animation

In addition to rotating the agent's animation shape according to the direction of movement in the XY plane, the animation shape can also automatically rotate vertically when moving. This type of autorotation is controlled by the Rotate vertically as well (along Z-axis) option, which becomes available when you select the Rotate animation towards movement option explained above.

In this case, we are talking about a deviation from the vertical Z-axis, or, more simply, a forward or backward inclination in the case of movement on an inclined plane.

Easier to explain with examples. This type of autorotation will be needed if you need to tilt back the box animation when the box agent is moving up the inclined conveyor.

And vice versa - when a pedestrian goes up the escalator, its figure should remain displayed vertically - for this type of agent, the vertical auto-rotate option should be disabled.

Changing rotation dynamically

Functions
Applies only to agents living in continuous or GIS space.
Function Description
double getRotation() Returns the current rotation angle (in radians) of the agent. The rotation angle is measured in radians (from animation point (1, 0), clockwise around (0, 0) point).
double getGISHeading() Returns current heading angle (measured in radians CW, starting from North direction) of the agent. Valid only for agents living in the GIS space.
void setRotation(double rotation) Sets the rotation angle (in radians) of the agent animation. Depending on automatic rotation setting, this rotation value may be overridden during the next call of moveTo() function or during the current movement.

rotation — the rotation angle of the agent in radians (measured from animation point (1, 0), clockwise around (0, 0) point)
boolean isAutomaticHorizontalRotation() Returns true if the agent is set to be rotated during movement, false otherwise.
void setAutomaticHorizontalRotation(boolean yes) Defines whether the agent animation should be automatically turned towards the target during the agent movement.

yes — if true, the agent's animation will turn towards the target during the agent movement, if false - not
double getVerticalRotation() Returns the current vertical rotation angle of the agent in continuous space. The rotation angle is measured in radians around Y axis (CW from +Z to +X).
void setVerticalRotation(double rotation) Sets the vertical rotation (angle in radians), along Z-axis of the agent animation in continuous space.
boolean isAutomaticVerticalRotation() Returns true if the agent is set to be automatically rotated vertically (along Z-axis), i.e. inclined toward/backward when the agent moves along the inclined plane (typical example - a box transported by a sloped conveyor), false otherwise (e.g. a passenger going upstairs).
void setAutomaticVerticalRotation(boolean yes) Defines whether the agent animation should be automatically inclined toward/backward when the agent moves along the inclined plane.

yes — if true, the agent's animation will be rotated vertically, if false - not
How can we improve this article?