{"name":"calculatePath","operator":null,"title":"calculatePath","type":"command","url":"https://community.bistudio.com/wiki/calculatePath","revid":376951,"updated":"2026-01-01T04:02:40Z","groups":["Object Manipulation"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.94"}],"since":{"game":"arma3","name":"Arma 3","version":"1.94"},"arma3_since":"1.94","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Spawns an agent that will execute an AI path calculation and fire the `\"PathCalculated\"` event handler.\nThe vehicle type to simulate could be one of the following presets:\n- `\"man\"`: C_man_1\n- `\"car\"`: C_Offroad_01_F\n- `\"tank\"`: B_MBT_01_cannon_F\n- `\"wheeled_APC\"`: B_APC_Tracked_01_rcws_F\n- `\"boat\"`: C_Rubberboat\n- `\"plane\"`: B_Plane_CAS_01_dynamicLoadout_F\n- `\"helicopter\"`: B_Heli_Light_01_F\n\nIf the given vehicle type is not one of the above presets, the exact given type is used.\n\n> [!IMPORTANT]\n> 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:\n>\n> ```sqf\n> isNil { calculatePath [\"man\", \"safe\", _startPos, _endPos] addEventHandler [\"PathCalculated\", { hint str _this }] };\n> ```\n\n> [!NOTE]\n> If an exact path is desired, it is recommended to avoid this command and simply use the PathCalculated event handler.\n> Paths to long distances are typically calculated in segments. This command only gives the first calculated segment.","syntaxes":[{"syntax":"calculatePath [type, behaviour, from, to]","since":null,"effect":null,"exec":null,"params":[{"name":"type","type":"String","optional":false,"default":null,"description":"vehicle type to simulate (see description)","types":["String"],"since":null,"text":"type: String - vehicle type to simulate (see description)"},{"name":"behaviour","type":"String","optional":false,"default":null,"description":"AI behaviour, one of \"CARELESS\", \"SAFE\", \"AWARE\", \"COMBAT\" or \"STEALTH\"","types":["String"],"since":null,"text":"behaviour: String - AI behaviour, one of \"CARELESS\", \"SAFE\", \"AWARE\", \"COMBAT\" or \"STEALTH\""},{"name":"from","type":"Array","optional":false,"default":null,"description":"start position in format [x,y,z]","types":["Array"],"since":null,"text":"from: Array - start position in format [x,y,z]"},{"name":"to","type":"Array","optional":false,"default":null,"description":"end position in format [x,y,z]","types":["Array"],"since":null,"text":"to: Array - end position in format [x,y,z]"}],"returns":{"type":"Object","types":["Object"],"description":"the agent to add the `\"PathCalculated\"` Event Handler to.","text":"Object - the agent to add the `\"PathCalculated\"` Event Handler to."},"form":"unary","operator":null,"left":null,"right":{"text":"[type, behaviour, from, to]","types":["Array"]}}],"examples":[{"text":"```sqf\ncalculatePath [\"car\", \"safe\", [2150.67,5778.19,0], [2184.11,5802.28,0]];\n```","code":["calculatePath [\"car\", \"safe\", [2150.67,5778.19,0], [2184.11,5802.28,0]];"]},{"text":"Draws the path from South West to North East of Agia Marina:\n\n```sqf\n(calculatePath [\"man\", \"safe\", [2832.9,5927.79,0], [3107.46,6036.61,0]]) addEventHandler [\"PathCalculated\", {\n    {\n        private _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n        _marker setMarkerType \"mil_dot\";\n        _marker setMarkerText str _forEachIndex;\n    } forEach (_this select 1);\n}];\n```","code":["(calculatePath [\"man\", \"safe\", [2832.9,5927.79,0], [3107.46,6036.61,0]]) addEventHandler [\"PathCalculated\", {\n\t{\n\t\tprivate _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n\t\t_marker setMarkerType \"mil_dot\";\n\t\t_marker setMarkerText str _forEachIndex;\n\t} forEach (_this select 1);\n}];"]},{"text":"Alternative usage of calculatePath functionality that is free of the double execution bug (and calculatePath command):\n\n```sqf\nprivate _agent = createAgent [typeOf player, position player, [], 0, \"NONE\"];\n_agent addEventHandler [\"PathCalculated\",\n{ \n    { \n        private _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n        _marker setMarkerType \"mil_dot\";\n        _marker setMarkerText str _forEachIndex;\n    } \n    forEach (_this select 1);\n}];\n_agent setDestination [player getRelPos [500, 0], \"LEADER PLANNED\", true];\n```","code":["private _agent = createAgent [typeOf player, position player, [], 0, \"NONE\"];\n_agent addEventHandler [\"PathCalculated\",\n{ \n\t{ \n\t\tprivate _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n\t\t_marker setMarkerType \"mil_dot\";\n\t\t_marker setMarkerText str _forEachIndex;\n\t} \n\tforEach (_this select 1);\n}];\n_agent setDestination [player getRelPos [500, 0], \"LEADER PLANNED\", true];"]},{"text":"Same as above but for a vehicle:\n\n```sqf\nprivate _agent = createAgent [typeOf player, position player, [], 0, \"NONE\"];\nprivate _car = \"B_Quadbike_01_F\" createVehicle position player;\n_agent moveInDriver _car;\n_agent addEventHandler [\"PathCalculated\",\n{ \n    { \n        private _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n        _marker setMarkerType \"mil_dot\";\n        _marker setMarkerText str _forEachIndex;\n    } \n    forEach (_this select 1);\n}];\n_agent setDestination [player getRelPos [500, 0], \"LEADER PLANNED\", true];\n```","code":["private _agent = createAgent [typeOf player, position player, [], 0, \"NONE\"];\nprivate _car = \"B_Quadbike_01_F\" createVehicle position player;\n_agent moveInDriver _car;\n_agent addEventHandler [\"PathCalculated\",\n{ \n\t{ \n\t\tprivate _marker = createMarker [\"marker\" + str _forEachIndex, _x];\n\t\t_marker setMarkerType \"mil_dot\";\n\t\t_marker setMarkerText str _forEachIndex;\n\t} \n\tforEach (_this select 1);\n}];\n_agent setDestination [player getRelPos [500, 0], \"LEADER PLANNED\", true];"]}],"multiplayer":null,"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.\nSee **Example 3 & 4** for a workaround.","aliases":[],"see_also":["setDriveOnPath","setDestination"],"notes":[{"user":"Tankbuster","date":"2019-06-06T10:28:00Z","text":"When using this command to get the predicted path of vehicles driving and having them stay on roads (not go cross country) is important,\nthe best vehicle to use is \"wheeled_APC\" and careless behaviour."}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Object Manipulation","Introduced with Arma 3 version 1.94","Scripting Commands"]}