{"name":"lineIntersectsObjs","title":"lineIntersectsObjs","type":"command","url":"https://community.bistudio.com/wiki/lineIntersectsObjs","revid":377627,"updated":"2026-01-02T08:52:08Z","groups":["Math - Geometry"],"status":"ok","games":{"arma3":"1.10"},"since":"arma3 1.10","arma3_since":"1.10","locality":{"argument":"global"},"description":"Returns a list of objects intersected by the line from *begPos* to *endPos*. Since Arma 3 v2.20, there is an alternative syntax that does multiple checks in parallel, faster than multiple calls.","syntaxes":[{"syntax":"lineIntersectsObjs [begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]","params":[{"name":"begPos","type":"PositionASL","description":"virtual line start","type_expr":"PositionASL"},{"name":"endPos","type":"PositionASL","description":"virtual line end","type_expr":"PositionASL"},{"name":"ignoreObj1","type":"Object","optional":true,"description":"object to ignore","type_expr":"Object","text":"ignoreObj1: Object - (Optional) - object to ignore"},{"name":"ignoreObj2","type":"Object","optional":true,"description":"object to ignore","type_expr":"Object","text":"ignoreObj2: Object - (Optional) - object to ignore"},{"name":"sortByDistance","type":"Boolean","optional":true,"description":"true: furthest object first, closest object last; false: unsorted","type_expr":"Boolean","text":"sortByDistance: Boolean - (Optional) - true: furthest object first, closest object last; false: unsorted"},{"name":"flags","type":"Number","optional":true,"description":"1 - CF_ONLY_WATER\n- 2 - CF_NEAREST_CONTACT\n- 4 - CF_ONLY_STATIC\n- 8 - CF_ONLY_DYNAMIC\n- 16 - CF_FIRST_CONTACT\n- 32 - CF_ALL_OBJECTS (Usable only with CF_FIRST_CONTACT and it will check one contact per object)\n\nFlags can be combined: 2 + 4 = 6 is CF_NEAREST_OBJECT + CF_ONLY_STATIC","type_expr":"Number","text":"flags: Number - (Optional)\n\n- 1 - CF_ONLY_WATER\n- 2 - CF_NEAREST_CONTACT\n- 4 - CF_ONLY_STATIC\n- 8 - CF_ONLY_DYNAMIC\n- 16 - CF_FIRST_CONTACT\n- 32 - CF_ALL_OBJECTS (Usable only with CF_FIRST_CONTACT and it will check one contact per object)\n\nFlags can be combined: 2 + 4 = 6 is CF_NEAREST_OBJECT + CF_ONLY_STATIC"}],"returns":{"type":"Array of Objects","type_expr":"Array<Object>","description":"intersecting objects"},"form":"unary","right":{"text":"[begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]"}},{"syntax":"lineIntersectsObjs [[element1, element2, ...]]","since":"arma3 2.20","params":[{"name":"elementN","type":"Array with [begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]","description":"Array with [begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]\n\n- begPos: PositionASL - virtual line start\n- endPos: PositionASL - virtual line end\n- ignoreObj1: Object - (Optional) - object to ignore\n- ignoreObj2: Object - (Optional) - object to ignore\n- sortByDistance: Boolean - (Optional) - true: furthest object first, closest object last; false: unsorted\n- flags: Number - (Optional)\n  - 1 - CF_ONLY_WATER\n  - 2 - CF_NEAREST_CONTACT\n  - 4 - CF_ONLY_STATIC\n  - 8 - CF_ONLY_DYNAMIC\n  - 16 - CF_FIRST_CONTACT\n  - 32 - CF_ALL_OBJECTS (Usable only with CF_FIRST_CONTACT and it will check one contact per object)\n\nFlags can be combined: 2 + 4 = 6 is CF_NEAREST_OBJECT + CF_ONLY_STATIC","type_expr":"Array","text":"elementN: Array with [begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]\n\n- begPos: PositionASL - virtual line start\n- endPos: PositionASL - virtual line end\n- ignoreObj1: Object - (Optional) - object to ignore\n- ignoreObj2: Object - (Optional) - object to ignore\n- sortByDistance: Boolean - (Optional) - true: furthest object first, closest object last; false: unsorted\n- flags: Number - (Optional)\n  - 1 - CF_ONLY_WATER\n  - 2 - CF_NEAREST_CONTACT\n  - 4 - CF_ONLY_STATIC\n  - 8 - CF_ONLY_DYNAMIC\n  - 16 - CF_FIRST_CONTACT\n  - 32 - CF_ALL_OBJECTS (Usable only with CF_FIRST_CONTACT and it will check one contact per object)\n\nFlags can be combined: 2 + 4 = 6 is CF_NEAREST_OBJECT + CF_ONLY_STATIC"}],"returns":{"type":"Array","type_expr":"Array","description":"with [result1, result2, ...] - each result is an Array of intersecting objects for the Nth element","text":"Array with [result1, result2, ...] - each result is an Array of intersecting objects for the Nth element"},"form":"unary","right":{"text":"[[element1, element2, ...]]"}}],"examples":[{"text":"```sqf\ndata = [];\ndisplayFunction = {\n    {\n        data set [_foreachindex, lineIntersectsObjs [eyePos player, ATLToASL screenToWorld [0.5, 0.5], objNull, objNull, false, _x]];\n    } forEach [1, 2, 4, 8, 16, 32];\n\n    hintSilent format [\"ONLY_WATER: %1\\nNEAREST_CONTACT: %2\\nONLY_STATIC: %3\\nONLY_DYNAMIC: %4\\nFIRST_CONTACT: %5\\nALL_OBJECTS: %6\",\n    data select 0, data select 1, data select 2, data select 3, data select 4, data select 5];\n};\n\n[\"sample_id\", \"onEachFrame\", \"displayFunction\"] call BIS_fnc_addStackedEventHandler;\n// example display objects' array in the middle of the screen sorted by 6 flags\n```","code":["data = [];\ndisplayFunction = {\n\t{\n\t\tdata set [_foreachindex, lineIntersectsObjs [eyePos player, ATLToASL screenToWorld [0.5, 0.5], objNull, objNull, false, _x]];\n\t} forEach [1, 2, 4, 8, 16, 32];\n\n\thintSilent format [\"ONLY_WATER: %1\\nNEAREST_CONTACT: %2\\nONLY_STATIC: %3\\nONLY_DYNAMIC: %4\\nFIRST_CONTACT: %5\\nALL_OBJECTS: %6\",\n\tdata select 0, data select 1, data select 2, data select 3, data select 4, data select 5];\n};\n\n[\"sample_id\", \"onEachFrame\", \"displayFunction\"] call BIS_fnc_addStackedEventHandler;\n// example display objects' array in the middle of the screen sorted by 6 flags"]},{"text":"Alternative syntax to check intersections in parallel:\n\n```sqf\nprivate _enemies = units opfor;\nprivate _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };\nprivate _result = lineIntersectsObjs [_enemyDataArray];\n```","code":["private _enemies = units opfor;\nprivate _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };\nprivate _result = lineIntersectsObjs [_enemyDataArray];"]}],"see_also":["lineIntersectsSurfaces","lineIntersectsWith","lineIntersects","terrainIntersectASL","terrainIntersectAtASL","terrainIntersect","intersect","cursorObject","cursorTarget","checkVisibility"],"notes":[{"user":"AgentRev","date":"2016-03-29T06:07:00Z","text":"Distance sorting is relative to object model center, and not intersect position."}]}