Skip to content

A3D_WorldToScreen

imshooter edited this page Oct 17, 2026 · 1 revision

Find where a point of the world shows on the screen of a player.

A point beside the screen gets coordinates beyond it.

native bool:A3D_WorldToScreen(playerid, Float:x, Float:y, Float:z, &Float:screenX, &Float:screenY);

Parameters

Parameter Description
playerid Player whose screen it is.
Float:x Point on the X axis.
Float:y Point on the Y axis.
Float:z Point on the Z axis.
&Float:screenX Where it shows across the screen.
&Float:screenY Where it shows down the screen.

Returns

  • true when the point lies in front of the camera.
  • false when it lies behind it, or the player sent no camera yet.

Remarks

The coordinates are those of text draws: 640 units across and 448 down, from the top left corner, whatever the resolution of the player. The screen explains how they are worked out from the camera the client sends.

A point beside or above the screen gets coordinates beyond it, which lets an arrow at the edge point to it. A point behind the camera gets none and the native returns false. Nothing is tested in between, so the point may be hidden by a wall. A3D_IsPointOnScreen can test that.

Example

Keeps a mark over a vehicle on the screen of a player.

static PlayerText:gMark[MAX_PLAYERS] = { INVALID_PLAYER_TEXT_DRAW, ... };

forward @Mark_Update(playerid, vehicleid);
public @Mark_Update(playerid, vehicleid) {
    new
        Float:x,
        Float:y,
        Float:z,
        Float:screenX,
        Float:screenY
    ;

    GetVehiclePos(vehicleid, x, y, z);

    if (!A3D_WorldToScreen(playerid, x, y, z + 1.5, screenX, screenY)) {
        PlayerTextDrawHide(playerid, gMark[playerid]);

        return 1;
    }

    PlayerTextDrawSetPos(playerid, gMark[playerid], screenX, screenY);
    PlayerTextDrawShow(playerid, gMark[playerid]);

    return 1;
}

stock MarkVehicle(playerid, vehicleid) {
    gMark[playerid] = CreatePlayerTextDraw(playerid, 0.0, 0.0, "V");
    SetTimerEx("@Mark_Update", 100, true, "ii", playerid, vehicleid);
}

Related

  • A3D_ScreenToWorld: Find the direction a point of the screen of a player looks into, from the position of their camera.
  • A3D_IsPointOnScreen: Whether a point shows on the screen of a player.
  • A3D_GetPlayersOnScreen: Find the players on the screen of a player, nearest first, in the same virtual world and interior.

Home

Guides

Reference

Functions

Creating objects
Motion
Placement
Behaviour
Display and data
Rays
Shapes
Players, vehicles and actors
Map probes
Screen
Map objects
Water
Models and surfaces
Rotations and offsets
Vehicles
Routes
Route display
Walking
Callbacks

Clone this wiki locally