Skip to content

A3D_GetPlayerTarget

imshooter edited this page Oct 17, 2026 · 1 revision

Find what a player looks at, from their camera.

Reads the camera the client last sent. The player and the vehicle they are in are never hit.

native bool:A3D_GetPlayerTarget(
    playerid,
    &Float:x,
    &Float:y,
    &Float:z,
    &A3D_HIT:type = A3D_HIT_MAP,
    &hitid = 0,
    &material = 0,
    Float:range = 100.0,
    A3D_COLLIDE:flags = A3D_COLLIDE_ALL
);

Parameters

Parameter Description Default
playerid Player who looks.
&Float:x Point looked at on the X axis.
&Float:y Point looked at on the Y axis.
&Float:z Point looked at on the Z axis.
&A3D_HIT:type What is looked at. A3D_HIT_MAP
&hitid Model of the map object, or the physics object, static object, player, vehicle or actor looked at. 0
&material Surface of the game looked at, see A3D_GetMaterialName. 0
Float:range How far to look. 100.0
A3D_COLLIDE:flags What may be looked at. A3D_COLLIDE_ALL

Returns

  • true when something is looked at within range.
  • false when nothing, or the player is not connected or sent no camera yet.

Remarks

The ray starts at the camera of the player and follows its direction, as the client last sent them. The player and the vehicle they are in are never hit, so a camera behind the player looks past them.

The client sends its camera while on foot. Bots of the NPC component send none, and a player who has just spawned may not have sent one yet. Both return false. The screen explains where the camera data comes from.

Example

Shoves the physics object a player looks at, when it is near.

public OnPlayerKeyStateChange(playerid, KEY:newkeys, KEY:oldkeys) {
    if (!(newkeys & KEY_YES)) {
        return 1;
    }

    new
        Float:x,
        Float:y,
        Float:z,
        A3D_HIT:type,
        hitid,
        material
    ;

    if (!A3D_GetPlayerTarget(playerid, x, y, z, type, hitid, material, 4.0)) {
        return 1;
    }

    if (type != A3D_HIT_OBJECT) {
        return 1;
    }

    A3D_ApplyImpulse(Physic:hitid, 0.0, 0.0, 30.0);

    return 1;
}

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_RayCast: Find the first thing a segment between two points hits.
  • 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