GraphicsClient2 outputs

getScreenCoordFromWorldCoord

GET_SCREEN_COORD_FROM_WORLD_COORD0x34E82F05DF2974F5

The GTA V native GET_SCREEN_COORD_FROM_WORLD_COORD of the GRAPHICS namespace, as LS:MP client scripts call it: the global function getScreenCoordFromWorldCoord, in JavaScript and in Lua.

SignatureJavaScript
getScreenCoordFromWorldCoord(
  worldX: number,
  worldY: number,
  worldZ: number
): [ok: boolean, screenX: number, screenY: number]
SignatureLua
getScreenCoordFromWorldCoord(
  worldX: number,
  worldY: number,
  worldZ: number
): boolean, number, number

Usage

JavaScript
const [ok, screenX, screenY] = getScreenCoordFromWorldCoord(worldX, worldY, worldZ);
Lua
local ok, screenX, screenY = getScreenCoordFromWorldCoord(worldX, worldY, worldZ)

Three consecutive numbers can be given as one vector: { x, y, z } (or [x, y, z]) in JavaScript, a Vector3 in Lua.

JavaScript · with vectors
const [ok, screenX, screenY] = getScreenCoordFromWorldCoord(world);
Lua · with vectors
local ok, screenX, screenY = getScreenCoordFromWorldCoord(world)

Parameters

ParameterTypeJavaScriptLua
worldXfloatnumbernumber
worldYfloatnumbernumber
worldZfloatnumbernumber

Returns

3 values, in this order: an array in JavaScript, multiple return values in Lua.

#ValueTypeJavaScriptLuaDescription
1okBOOLbooleanbooleanThe native’s own return value.
2screenXfloatnumbernumberoutput
3screenYfloatnumbernumberoutput

On LS:MP

✓
Friendlier helper

lsmp.worldToScreen returns the same values as an object: { onScreen, x, y }.

Notes

From the community native database. Names are LS:MP’s; samples may be written for C++ or another framework.

Convert a world coordinate into its relative screen coordinate. (WorldToScreen)

Returns a boolean; whether or not the operation was successful. It will return false if the coordinates given are not visible to the rendering camera.

For .NET users...

VB:

Public Shared Function World3DToScreen2d(pos as vector3) As Vector2

        Dim x2dp, y2dp As New Native.OutputArgument

        Native.Function.Call(Of Boolean)(Native.Hash.GET_SCREEN_COORD_FROM_WORLD_COORD , pos.x, pos.y, pos.z, x2dp, y2dp)
        Return New Vector2(x2dp.GetResult(Of Single), y2dp.GetResult(Of Single))

    End Function

C#:

Vector2 World3DToScreen2d(Vector3 pos)
    {
        var x2dp = new OutputArgument();
        var y2dp = new OutputArgument();

        Function.Call<bool>(Hash.GET_SCREEN_COORD_FROM_WORLD_COORD , pos.X, pos.Y, pos.Z, x2dp, y2dp);
        return new Vector2(x2dp.GetResult<float>(), y2dp.GetResult<float>());
    }
//USE VERY SMALL VALUES FOR THE SCALE OF RECTS/TEXT because it is dramatically larger on screen than in 3D, e.g '0.05' small.

It does seem however that calling setDrawOrigin then your natives, then ending it. Seems to work better for certain things such as keeping boxes around people for a predator missile e.g.

Reference

Namespace
Graphics GRAPHICS
In the game
BOOL GET_SCREEN_COORD_FROM_WORLD_COORD(float worldX, float worldY, float worldZ, float* screenX, float* screenY)
Hash
0x34E82F05DF2974F5
Formerly
_WORLD3D_TO_SCREEN2D

Open in the interactive natives reference