lineIntersectsWith: Difference between revisions

From Bohemia Interactive Community
(Add alternative syntax for running multiple intersections in parallel. Minor typo corrections. Reordered see also commands to be grouped and consistent across lineIntersects pages)
mNo edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 19: Line 19:
* Max hardcoded distance is 1000m.
* Max hardcoded distance is 1000m.
}}
}}
Since {{GVI|arma3|2.20|size= 0.75}}, there is an alternative syntax that does multiple checks at once, faster than multiple calls.
Since {{GVI|arma3|2.20|size= 0.75}}, there is an alternative syntax that does multiple checks in parallel, faster than multiple calls.


|s1= [[lineIntersectsWith]] [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]
|s1= [[lineIntersectsWith]] [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]


|p1= begPos: [[Array]] format [[Position#PositionASL|PositionASL]] - virtual line start
|p1= begPos: [[Position#PositionASL|PositionASL]] - virtual line start


|p2= endPos: [[Array]] format [[Position#PositionASL|PositionASL]] - virtual line end
|p2= endPos: [[Position#PositionASL|PositionASL]] - virtual line end


|p3= 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.
|p3= 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.
Line 33: Line 33:
|p5= sortByDistance: [[Boolean]] - (Optional) [[true]]: sort by '''desc'''ending distance (furthermost object first, closest object last); [[false]]: unsorted
|p5= sortByDistance: [[Boolean]] - (Optional) [[true]]: sort by '''desc'''ending distance (furthermost object first, closest object last); [[false]]: unsorted


|r1= [[Array]] - intersecting objects
|r1= [[Array]] of [[Object]]s - intersecting objects


|s2= [[lineIntersectsWith]] [element1, element2, ...]
|s2= [[lineIntersectsWith]] <noWiki>[[</nowiki>element1, element2, ...<noWiki>]]</noWiki>


|s2since= arma3 2.20
|s2since= arma3 2.20


|p21= elementN: [[Array]] format [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]
|p21= elementN: [[Array]] with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]
* begPos: [[Array]] format [[Position#PositionASL|PositionASL]] - virtual line start
* begPos: [[Position#PositionASL|PositionASL]] - virtual line start
* endPos: [[Array]] format [[Position#PositionASL|PositionASL]] - virtual line end
* endPos: [[Position#PositionASL|PositionASL]] - virtual line end
* 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.
* 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.
* 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
* 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
* sortByDistance: [[Boolean]] - (Optional) [[true]]: sort by '''desc'''ending distance (furthermost object first, closest object last); [[false]]: unsorted
* sortByDistance: [[Boolean]] - (Optional) [[true]]: sort by '''desc'''ending distance (furthermost object first, closest object last); [[false]]: unsorted


|r2= [[Array]] format [result1, result2, ...] - each result is an [[Array]] of intersecting objects for the Nth element
|r2= [[Array]] with [result1, result2, ...] - each result is an [[Array]] of intersecting objects for the Nth element


|x1= <sqf>_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5]];</sqf>
|x1= <sqf>_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5]];</sqf>
Line 60: Line 60:
private _enemies = units opfor;
private _enemies = units opfor;
private _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };
private _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };
private _result = lineIntersectsWith _enemyDataArray;
private _result = lineIntersectsWith [_enemyDataArray];
</sqf>
</sqf>



Latest revision as of 17:54, 3 April 2026

Hover & click on the images for description

Description

Description:
Returns objects intersecting with the virtual line from begPos to endPos. By default, the resulting array of intersecting objects is unsorted (see sortByDistance).
  • Does not work under water.
  • Max hardcoded distance is 1000m.
Since Arma 3 logo black.png 2.20, there is an alternative syntax that does multiple checks in parallel, faster than multiple calls.
Groups:
Math - Geometry

Syntax

Syntax:
lineIntersectsWith [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]
Parameters:
begPos: PositionASL - virtual line start
endPos: PositionASL - virtual line end
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.
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
sortByDistance: Boolean - (Optional) true: sort by descending distance (furthermost object first, closest object last); false: unsorted
Return Value:
Array of Objects - intersecting objects

Alternative Syntax

Syntax:
lineIntersectsWith [[element1, element2, ...]]
Parameters:
elementN: Array with [begPos, endPos, objIgnore1, objIgnore2, sortByDistance]
  • begPos: PositionASL - virtual line start
  • endPos: PositionASL - virtual line end
  • 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.
  • 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
  • sortByDistance: Boolean - (Optional) true: sort by descending distance (furthermost object first, closest object last); false: unsorted
Return Value:
Array with [result1, result2, ...] - each result is an Array of intersecting objects for the Nth element

Examples

Example 1:
_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5]];
Example 2:
Sort by distance:
_objects = lineIntersectsWith [eyePos player, AGLToASL screenToWorld [0.5, 0.5], objNull, objNull, true];
Example 3:
Ignore objects:
_objects = lineIntersectsWith [eyePos player, aimPos chopper, player, chopper];
Example 4:
Alternative syntax to check intersections in parallel:
private _enemies = units opfor; private _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] }; private _result = lineIntersectsWith [_enemyDataArray];

Additional Information

See also:
lineIntersectsSurfaces lineIntersectsObjs lineIntersects terrainIntersect terrainIntersectASL terrainIntersectAtASL intersect cursorObject cursorTarget checkVisibility

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord.
Only post proven facts here! Add Note
Lou Montana - c
Posted on May 31, 2012 - 10:50 (UTC)
Please note the difference :
  • terrainIntersect
  • terrainIntersectASL
  • lineIntersects
  • lineIntersectsWith
  • lineIntersectsObjs
  • intersect