Skip to content

A3D_SweepSphere

imshooter edited this page Oct 17, 2026 · 1 revision

Move a sphere along a segment and find where it first touches something.

Like A3D_RayCast for something with a size: a camera that must not enter walls, or a spot where a thrown object would stop.

native bool:A3D_SweepSphere(
    Float:radius,
    Float:startX,
    Float:startY,
    Float:startZ,
    Float:endX,
    Float:endY,
    Float:endZ,
    &Float:x,
    &Float:y,
    &Float:z,
    &A3D_HIT:type = A3D_HIT_MAP,
    &hitid = 0,
    &material = 0,
    worldid = -1,
    A3D_COLLIDE:flags = A3D_COLLIDE_ALL
);

Parameters

Parameter Description Default
Float:radius Radius of the sphere.
Float:startX Start of its centre on the X axis.
Float:startY Start on the Y axis.
Float:startZ Start on the Z axis.
Float:endX End of its centre on the X axis.
Float:endY End on the Y axis.
Float:endZ End on the Z axis.
&Float:x Centre where it stops on the X axis, or the end when nothing is touched.
&Float:y Centre on the Y axis.
&Float:z Centre on the Z axis.
&A3D_HIT:type What it touched. A3D_HIT_MAP
&hitid Model of the map object, or the physics object, static object, player, vehicle or actor touched. 0
&material Surface of the game touched, see A3D_GetMaterialName. 0
worldid Virtual world to look in, or -1 for every world. -1
A3D_COLLIDE:flags What the sphere may touch. A3D_COLLIDE_ALL

Returns

  • true when the sphere touched something.
  • false when it reached the end, or the radius is not positive.

Remarks

A ray has no thickness and slips through gaps a real object would not fit in. A sweep moves a whole sphere along the segment and stops it at the first touch, with x, y and z at its centre then. When nothing is touched, the end of the segment is written and the native returns false, so the point is always usable.

With A3D_COLLIDE_WATER, the sweep also stops where its centre reaches the surface of the water. Everything else follows A3D_RayCast.

Example

Places a camera behind a player without letting it enter a wall.

stock SetCameraBehind(playerid, Float:distance) {
    new
        Float:x,
        Float:y,
        Float:z,
        Float:angle,
        Float:cameraX,
        Float:cameraY,
        Float:cameraZ
    ;

    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, angle);
    A3D_SweepSphere(0.3, x, y, z + 0.8, x + distance * floatsin(angle, degrees), y - distance * floatcos(angle, degrees), z + 1.5, cameraX, cameraY, cameraZ, .worldid = GetPlayerVirtualWorld(playerid), .flags = A3D_COLLIDE_MAP | A3D_COLLIDE_STATIC);
    SetPlayerCameraPos(playerid, cameraX, cameraY, cameraZ);
    SetPlayerCameraLookAt(playerid, x, y, z + 0.8);
}

Related

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