Arma 3 Scripting

Command in Object Manipulation

calculatePath

Also available as Markdown and JSON, or read the original wiki page.

Description

Spawns an agent that will execute an AI path calculation and fire the "PathCalculated" event handler. The vehicle type to simulate could be one of the following presets:

If the given vehicle type is not one of the above presets, the exact given type is used.

Important

In order to guarantee that the event handler is added to the result of this command before the path is calculated, use isNil to run the code in an Unscheduled Environment:

isNil { calculatePath ["man", "safe", _startPos, _endPos] addEventHandler ["PathCalculated", { hint str _this }] };

Note

If an exact path is desired, it is recommended to avoid this command and simply use the PathCalculated event handler. Paths to long distances are typically calculated in segments. This command only gives the first calculated segment.

Syntax

calculatePath [type, behaviour, from, to]

Parameters:

Returns: Object - the agent to add the "PathCalculated" Event Handler to.

Examples

Example 1

calculatePath ["car", "safe", [2150.67,5778.19,0], [2184.11,5802.28,0]];

Example 2

Draws the path from South West to North East of Agia Marina:

(calculatePath ["man", "safe", [2832.9,5927.79,0], [3107.46,6036.61,0]]) addEventHandler ["PathCalculated", {
    {
        private _marker = createMarker ["marker" + str _forEachIndex, _x];
        _marker setMarkerType "mil_dot";
        _marker setMarkerText str _forEachIndex;
    } forEach (_this select 1);
}];

Example 3

Alternative usage of calculatePath functionality that is free of the double execution bug (and calculatePath command):

private _agent = createAgent [typeOf player, position player, [], 0, "NONE"];
_agent addEventHandler ["PathCalculated",
{ 
    { 
        private _marker = createMarker ["marker" + str _forEachIndex, _x];
        _marker setMarkerType "mil_dot";
        _marker setMarkerText str _forEachIndex;
    } 
    forEach (_this select 1);
}];
_agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];

Example 4

Same as above but for a vehicle:

private _agent = createAgent [typeOf player, position player, [], 0, "NONE"];
private _car = "B_Quadbike_01_F" createVehicle position player;
_agent moveInDriver _car;
_agent addEventHandler ["PathCalculated",
{ 
    { 
        private _marker = createMarker ["marker" + str _forEachIndex, _x];
        _marker setMarkerType "mil_dot";
        _marker setMarkerText str _forEachIndex;
    } 
    forEach (_this select 1);
}];
_agent setDestination [player getRelPos [500, 0], "LEADER PLANNED", true];

Problems

For some unknown reason, the "PathCalculated" Event Handler is fired twice, first with the calculated path and second with an array consisting of 2 elements, which are identical and are equal to the end point. See Example 3 & 4 for a workaround.

See also

setDriveOnPath · setDestination

Community notes

Tankbuster

When using this command to get the predicted path of vehicles driving and having them stay on roads (not go cross country) is important, the best vehicle to use is "wheeled_APC" and careless behaviour.