Skip to content

A3D_PredictTrajectory

imshooter edited this page Oct 17, 2026 · 1 revision

Follow something thrown, such as a grenade, and find where it first lands.

The path is the curve of the throw under gravity, without air resistance. With a radius, a sphere of that size is followed and the point is its centre when it touches. Start outside the thrower, or leave A3D_COLLIDE_PLAYERS out of flags.

native bool:A3D_PredictTrajectory(
    Float:x,
    Float:y,
    Float:z,
    Float:vx,
    Float:vy,
    Float:vz,
    &Float:hitX,
    &Float:hitY,
    &Float:hitZ,
    &Float:time = 0.0,
    &A3D_HIT:type = A3D_HIT_MAP,
    &hitid = 0,
    &material = 0,
    Float:radius = 0.0,
    Float:gravity = 9.81,
    Float:duration = 10.0,
    worldid = -1,
    A3D_COLLIDE:flags = A3D_COLLIDE_ALL
);

Parameters

Parameter Description Default
Float:x Start on the X axis.
Float:y Start on the Y axis.
Float:z Start on the Z axis.
Float:vx Speed on the X axis, in metres per second.
Float:vy Speed on the Y axis.
Float:vz Speed on the Z axis.
&Float:hitX Point where it lands on the X axis.
&Float:hitY Point on the Y axis.
&Float:hitZ Point on the Z axis.
&Float:time Seconds it flies. 0.0
&A3D_HIT:type What it lands on. A3D_HIT_MAP
&hitid Model of the map object, or the physics object, static object, player, vehicle or actor. 0
&material Surface of the game it lands on. 0
Float:radius Radius of what is thrown, or 0.0 for a point. 0.0
Float:gravity Gravity in metres per second squared. 9.81
Float:duration Longest flight followed, in seconds. 10.0
worldid Virtual world to look in, or -1 for every world. -1
A3D_COLLIDE:flags What it may land on. A3D_COLLIDE_ALL

Returns

  • true when it lands within duration.
  • false when it flies on, or falls below 3dandreas.floor.

How it works

The flight is cut into steps of 1/30 second. Each step follows the straight line between two points of the curve, as a ray or, with a radius, as a sphere sweep. A step strays from the curve by under two millimetres at the gravity of the game, so the landing point lies on the curve. time is measured along the step that lands.

The throw has no air resistance and no bounce. The first touch is the landing. The search ends at duration, or when the path falls below 3dandreas.floor.

A throw that lands 60 metres away costs about 60 microseconds.

Notes

  • Start the throw outside the thrower, or leave A3D_COLLIDE_PLAYERS out of the flags, or it lands on the thrower at once.
  • With A3D_COLLIDE_WATER in the flags, the throw lands on the water. Without it, it lands on the bottom.
  • The result matches a physics object thrown the same way only until it first touches something, since the object then bounces and rolls.

Example

Marks where a grenade thrown where the camera looks would land.

stock MarkGrenade(playerid) {
    new
        Float:x,
        Float:y,
        Float:z,
        Float:frontX,
        Float:frontY,
        Float:frontZ,
        Float:hitX,
        Float:hitY,
        Float:hitZ,
        Float:time,
        A3D_HIT:type,
        hitid,
        material
    ;

    GetPlayerPos(playerid, x, y, z);
    GetPlayerCameraFrontVector(playerid, frontX, frontY, frontZ);

    if (!A3D_PredictTrajectory(x, y, z + 0.7, frontX * 15.0, frontY * 15.0, frontZ * 15.0 + 4.0, hitX, hitY, hitZ, time, type, hitid, material, 0.1, .worldid = GetPlayerVirtualWorld(playerid), .flags = A3D_COLLIDE_ALL & ~A3D_COLLIDE_PLAYERS)) {
        return;
    }

    SetPlayerCheckpoint(playerid, hitX, hitY, hitZ, 1.0);
}

Related

  • A3D_SweepSphere: Move a sphere along a segment and find where it first touches something.
  • A3D_RayCast: Find the first thing a segment between two points hits.
  • A3D_SetGravity: Set how strongly a moving physics object falls.

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