Skip to content

A3D_ScreenToWorld

imshooter edited this page Oct 17, 2026 · 1 revision

Find the direction a point of the screen of a player looks into, from the position of their camera.

native bool:A3D_ScreenToWorld(
    playerid,
    Float:screenX,
    Float:screenY,
    &Float:directionX,
    &Float:directionY,
    &Float:directionZ
);

Parameters

Parameter Description
playerid Player whose screen it is.
Float:screenX Point across the screen.
Float:screenY Point down the screen.
&Float:directionX Direction on the X axis, one metre long.
&Float:directionY Direction on the Y axis.
&Float:directionZ Direction on the Z axis.

Returns

  • true when the direction was written.
  • false when the player sent no camera yet.

Remarks

The direction starts at the camera of the player, which GetPlayerCameraPos gives. The centre of the screen, 320.0 and 224.0, gives the direction the camera looks in. A point outside the screen gives a direction outside the view.

A3D_GetScreenTarget follows the direction to what it meets. This native gives the direction for other uses, such as a sweep or a throw.

Example

Throws a ball towards a point of the screen.

stock ThrowTowards(playerid, Float:screenX, Float:screenY) {
    new
        Float:x,
        Float:y,
        Float:z,
        Float:directionX,
        Float:directionY,
        Float:directionZ,
        Physic:ball
    ;

    if (!A3D_ScreenToWorld(playerid, screenX, screenY, directionX, directionY, directionZ)) {
        return;
    }

    GetPlayerPos(playerid, x, y, z);
    ball = A3D_CreateSphere(1598, 0.3, x + directionX, y + directionY, z + 0.6, 0.5, GetPlayerVirtualWorld(playerid));
    A3D_SetVelocity(ball, directionX * 15.0, directionY * 15.0, directionZ * 15.0);
}

Related

  • A3D_GetScreenTarget: Find what a point of the screen of a player shows, such as the place they clicked on a grid of text draws.
  • A3D_WorldToScreen: Find where a point of the world shows on the screen of a player.

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