RedM Natives

GET_WORLD_COORD_FROM_SCREEN_COORD

Converts a screen coordinate into its relative world coordinate.

Hash0xC81D0659
Runtime nameGetWorldCoordFromScreenCoord
NamespaceCFX
SideClient
NameOfficial
Docs

Signature

void GET_WORLD_COORD_FROM_SCREEN_COORD(float screenX, float screenY, Vector3* worldVector, Vector3* normalVector);

Parameters

NameTypeDescription
screenXfloat

A screen horizontal axis coordinate (0.0 - 1.0).

screenYfloat

A screen vertical axis coordinate (0.0 - 1.0).

worldVectorVector3*

The world coord vector pointer.

normalVectorVector3*

The screen normal vector pointer.

Returns void — A Vector3 representing the world coordinates relative to the specified screen coordinates and a screen plane normal Vector3 (normalised).

Description

Cfx.re native reference

Converts a screen coordinate into its relative world coordinate.

Usage

Lua
local worldVector, normalVector = GetWorldCoordFromScreenCoord(screenX, screenY)

-- always works, by hash
local worldVector, normalVector = Citizen.InvokeNative(0xc81d0659, screenX, screenY, Citizen.PointerValueVector(), Citizen.PointerValueVector())
JavaScript and C#
JavaScript
const [worldVector, normalVector] = GetWorldCoordFromScreenCoord(screenX, screenY);

// by hash
const [worldVector, normalVector] = Citizen.invokeNative('0xc81d0659', screenX + 0.0000001, screenY + 0.0000001, Citizen.pointerValueVector(), Citizen.pointerValueVector());
C#
var worldVector = new OutputArgument();
var normalVector = new OutputArgument();
Function.Call((Hash)0xc81d0659, screenX, screenY, worldVector, normalVector);
// worldVector.GetResult<Vector3>()
// normalVector.GetResult<Vector3>()
  • Float parameters: Lua integers (10, or whole numbers decoded from NUI/JSON) are sent as ints and read as garbage. Write 10.0 or value + 0.0. The generated JS wrappers add 0.0000001 to non-zero floats for the same reason.
  • Pointer (out) arguments are not passed in Lua/JS: their values are returned after the result, in order.

Examples

LUA · Cfx.re native reference
CreateThread(function()
  while true do
    local screenX = GetDisabledControlNormal(0, 239)
    local screenY = GetDisabledControlNormal(0, 240)

    local world, normal = GetWorldCoordFromScreenCoord(screenX, screenY)

    local depth = 10

    local target = world + normal * depth

    DrawSphere(target.x, target.y, target.z, 0.5, 255, 0, 0, 0.5)

    Wait(0)
  end
end)

Sources

Cfx.re native reference

Something wrong or missing? Contribute a verified note — corrections ship through pull requests.