{"name":"lineIntersectsWith","operator":null,"title":"lineIntersectsWith","type":"command","url":"https://community.bistudio.com/wiki/lineIntersectsWith","revid":378359,"updated":"2026-04-03T15:54:33Z","groups":["Math - Geometry"],"status":"ok","replaced_by":[],"games":[{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.62"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.62"},"arma3_since":"0.50","branch":null,"locality":{"argument":"global","effect":null,"server_exec":false},"exec":null,"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]","since":null,"effect":null,"exec":null,"params":[{"name":"begPos","type":"PositionASL","optional":false,"default":null,"description":"virtual line start","types":["PositionASL"],"since":null,"text":"begPos: PositionASL - virtual line start"},{"name":"endPos","type":"PositionASL","optional":false,"default":null,"description":"virtual line end","types":["PositionASL"],"since":null,"text":"endPos: PositionASL - virtual line end"},{"name":"objIgnore1","type":"Object","optional":true,"default":null,"description":"object to ignore. When testing intersections from an object/unit/vehicle, pass that object here to prevent intersections inside of the object.","types":["Object"],"since":null,"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,"default":null,"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","types":["Object"],"since":null,"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,"default":null,"description":"true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted","types":["Boolean"],"since":null,"text":"sortByDistance: Boolean - (Optional) true: sort by **desc**ending distance (furthermost object first, closest object last); false: unsorted"}],"returns":{"type":"Array of Objects","types":["Array","Object"],"description":"intersecting objects","text":"Array of Objects - intersecting objects"},"form":"unary","operator":null,"left":null,"right":{"text":"[begPos, endPos, objIgnore1, objIgnore2, sortByDistance]","types":["Array"]}},{"syntax":"lineIntersectsWith [[element1, element2, ...]]","since":"arma3 2.20","effect":null,"exec":null,"params":[{"name":"elementN","type":"Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]","optional":true,"default":null,"description":"Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]\n- begPos: PositionASL - virtual line start\n- endPos: PositionASL - virtual line end\n- objIgnore1: Object -  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","types":["Array"],"since":null,"text":"elementN: Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]\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 with [result1, result2, ...]","types":["Array"],"description":"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","operator":null,"left":null,"right":{"text":"[[element1, element2, ...]]","types":["Array"]}}],"examples":[{"text":"```sqf\n_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5]];\n```","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];"]}],"multiplayer":null,"problems":null,"aliases":[],"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- terrainIntersect\n- terrainIntersectASL\n- lineIntersect***s***\n- lineIntersect***s***With\n- lineIntersect***s***Objs\n- intersect"}],"categories":["Arma 2: Operation Arrowhead: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 3: Scripting Commands","Command Group: Math - Geometry","Introduced with Arma 2: Operation Arrowhead version 1.62","Scripting Commands","Take On Helicopters: Scripting Commands"]}