Arma 3 Scripting

Command in Math - Geometry

lineIntersectsObjs

Also available as Markdown and JSON, or read the original wiki page.

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.

Syntax

Syntax 1

lineIntersectsObjs [begPos, endPos, ignoreObj1, ignoreObj2, sortByDistance, flags]

Parameters:

Returns: Array of Objects - intersecting objects

Syntax 2

since arma3 2.20

lineIntersectsObjs [[element1, element2, ...]]

Parameters:

Returns: Array with [result1, result2, ...] - each result is an Array of intersecting objects for the Nth element

Examples

Example 1

data = [];
displayFunction = {
    {
        data set [_foreachindex, lineIntersectsObjs [eyePos player, ATLToASL screenToWorld [0.5, 0.5], objNull, objNull, false, _x]];
    } forEach [1, 2, 4, 8, 16, 32];

    hintSilent format ["ONLY_WATER: %1\nNEAREST_CONTACT: %2\nONLY_STATIC: %3\nONLY_DYNAMIC: %4\nFIRST_CONTACT: %5\nALL_OBJECTS: %6",
    data select 0, data select 1, data select 2, data select 3, data select 4, data select 5];
};

["sample_id", "onEachFrame", "displayFunction"] call BIS_fnc_addStackedEventHandler;
// example display objects' array in the middle of the screen sorted by 6 flags

Example 2

Alternative syntax to check intersections in parallel:

private _enemies = units opfor;
private _enemyDataArray = _enemies apply { [eyePos player, aimPos _x, player, _x, true] };
private _result = lineIntersectsObjs [_enemyDataArray];

See also

lineIntersectsSurfaces · lineIntersectsWith · lineIntersects · terrainIntersectASL · terrainIntersectAtASL · terrainIntersect · intersect · cursorObject · cursorTarget · checkVisibility

Community notes

AgentRev

Distance sorting is relative to object model center, and not intersect position.