{"name":"lineIntersectsWith","title":"lineIntersectsWith","type":"command","url":"https://community.bistudio.com/wiki/lineIntersectsWith","revid":378359,"updated":"2026-04-03T15:54:33Z","groups":["Math - Geometry"],"status":"ok","games":{"arma2oa":"1.62","tkoh":"1.00","arma3":"0.50"},"since":"arma2oa 1.62","arma3_since":"0.50","locality":{"argument":"global"},"description":"Returns objects intersecting with the virtual line from *begPos* to *endPos*. By default, the resulting array of intersecting objects is unsorted (see *sortByDistance*).\n\n> [!NOTE]\n> - Does not work under water.\n> - Max hardcoded distance is 1000m.\n\nSince Arma 3 v2.20, there is an alternative syntax that does multiple checks in parallel, faster than multiple calls.","syntaxes":[{"syntax":"lineIntersectsWith [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]","params":[{"name":"begPos","type":"PositionASL","description":"virtual line start","type_expr":"PositionASL"},{"name":"endPos","type":"PositionASL","description":"virtual line end","type_expr":"PositionASL"},{"name":"objIgnore1","type":"Object","optional":true,"description":"object to ignore. When testing intersections from an object/unit/vehicle, pass that object here to prevent intersections inside of the object.","type_expr":"Object","text":"objIgnore1: Object - (Optional) object to ignore. When testing intersections from an object/unit/vehicle, pass that object here to prevent intersections inside of the object."},{"name":"objIgnore2","type":"Object","optional":true,"description":"another object to ignore. When testing intersections of a line between two objects, pass the second object here to prevent intersections inside of it being reported","type_expr":"Object","text":"objIgnore2: Object - (Optional) another object to ignore. When testing intersections of a line between two objects, pass the second object here to prevent intersections inside of it being reported"},{"name":"sortByDistance","type":"Boolean","optional":true,"description":"true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted","type_expr":"Boolean","text":"sortByDistance: Boolean - (Optional) true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted"}],"returns":{"type":"Array of Objects","type_expr":"Array<Object>","description":"intersecting objects"},"form":"unary","right":{"text":"[begPos, endPos, objIgnore1, objIgnore2, sortByDistance]"}},{"syntax":"lineIntersectsWith [[element1, element2, ...]]","since":"arma3 2.20","params":[{"name":"elementN","type":"Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]","description":"Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]\n\n- begPos: PositionASL - virtual line start\n- endPos: PositionASL - virtual line end\n- objIgnore1: Object - (Optional) object to ignore. When testing intersections from an object/unit/vehicle, pass that object here to prevent intersections inside of the object.\n- objIgnore2: Object - (Optional) another object to ignore. When testing intersections of a line between two objects, pass the second object here to prevent intersections inside of it being reported\n- sortByDistance: Boolean - (Optional) true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted","type_expr":"Array","text":"elementN: Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]\n\n- begPos: PositionASL - virtual line start\n- endPos: PositionASL - virtual line end\n- objIgnore1: Object - (Optional) object to ignore. When testing intersections from an object/unit/vehicle, pass that object here to prevent intersections inside of the object.\n- objIgnore2: Object - (Optional) another object to ignore. When testing intersections of a line between two objects, pass the second object here to prevent intersections inside of it being reported\n- sortByDistance: Boolean - (Optional) true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted"}],"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":[{"code":["_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5]];"]},{"text":"Sort by distance:\n\n```sqf\n_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5], objNull, objNull, true];\n```","code":["_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5], objNull, objNull, true];"]},{"text":"Ignore objects:\n\n```sqf\n_objects = lineIntersectsWith [eyePos player, aimPos chopper, player, chopper];\n```","code":["_objects = lineIntersectsWith [eyePos player, aimPos chopper, player, chopper];"]},{"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 = lineIntersectsWith [_enemyDataArray];\n```","code":["private _enemies = units opfor;\nprivate _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };\nprivate _result = lineIntersectsWith [_enemyDataArray];"]}],"see_also":["lineIntersectsSurfaces","lineIntersectsObjs","lineIntersects","terrainIntersect","terrainIntersectASL","terrainIntersectAtASL","intersect","cursorObject","cursorTarget","checkVisibility"],"notes":[{"user":"Lou Montana","date":"2012-05-31T10:50:00Z","text":"Please note the difference :\n\n- terrainIntersect\n- terrainIntersectASL\n- lineIntersect***s***\n- lineIntersect***s***With\n- lineIntersect***s***Objs\n- intersect"}]}