Arma 3 Scripting

Command in Positions

screenToWorld

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

Description

Returns the position on landscape (PositionAGL) corresponding to the given point on screen (in UI coordinates).

Note

This command performs an intersection with the ground/water surface, from the camera position along the screenToWorldDirection vector up to viewDistance for terrain intersection and 2 * viewDistance for water intersection. In other words, it is similar to doing:

private _p1 = AGLToASL positionCameraToWorld [0, 0, 0];                    // camera position ASL
private _vector = screenToWorldDirection _screenPos;                    // "aim" vector
private _p2 = _p1 vectorAdd (_vector vectorMultiply viewDistance * 2);    // the ray does not go beyond 2 * view distance
ASLToAGL terrainIntersectAtASL [_p1, _p2]

Syntax

Syntax 1

screenToWorld screen

Parameters:

Returns: PositionAGL, world position on surface [x, y, 0]

Syntax 2

since arma3 2.18

camera screenToWorld position

Parameters:

Returns: PositionAGL, world position on surface [x,y,0]

Examples

Example 1

private _wPos = screenToWorld [0.5, 0.5];

Example 2

private _wPos = _myCamera screenToWorld [0.5, 0.5]; // since Arma 3 2.18

See also

SafeZone · worldToScreen · screenToWorldDirection