Skip to content

A3D_GetReflection

imshooter edited this page Oct 17, 2026 · 1 revision

Find the direction something takes after bouncing off a surface, such as a bullet that ricochets.

native bool:A3D_GetReflection(
    Float:directionX,
    Float:directionY,
    Float:directionZ,
    Float:normalX,
    Float:normalY,
    Float:normalZ,
    &Float:x,
    &Float:y,
    &Float:z
);

Parameters

Parameter Description
Float:directionX Direction before the bounce on the X axis.
Float:directionY Direction on the Y axis.
Float:directionZ Direction on the Z axis.
Float:normalX Normal of the surface on the X axis.
Float:normalY Normal on the Y axis.
Float:normalZ Normal on the Z axis.
&Float:x Direction after the bounce on the X axis, as long as before.
&Float:y Direction on the Y axis.
&Float:z Direction on the Z axis.

Returns

  • true when the direction was written.
  • false when the normal has no length.

Remarks

The direction mirrors on the surface: the part along the normal turns back and the part along the surface stays. Its length stays too, so a velocity reflects into the velocity after a perfect bounce.

Example

Follows a bullet that ricochets once off the map.

stock bool:GetRicochetEnd(Float:x, Float:y, Float:z, Float:directionX, Float:directionY, Float:directionZ, &Float:endX, &Float:endY, &Float:endZ) {
    new
        Float:hitX,
        Float:hitY,
        Float:hitZ,
        Float:normalX,
        Float:normalY,
        Float:normalZ,
        Float:bounceX,
        Float:bounceY,
        Float:bounceZ
    ;

    if (!A3D_RayCastNormal(x, y, z, x + directionX * 100.0, y + directionY * 100.0, z + directionZ * 100.0, hitX, hitY, hitZ, normalX, normalY, normalZ, .flags = A3D_COLLIDE_MAP)) {
        return false;
    }

    A3D_GetReflection(directionX, directionY, directionZ, normalX, normalY, normalZ, bounceX, bounceY, bounceZ);

    return A3D_RayCast(hitX, hitY, hitZ, hitX + bounceX * 50.0, hitY + bounceY * 50.0, hitZ + bounceZ * 50.0, endX, endY, endZ);
}

Related

  • A3D_RayCastNormal: Find the first thing a segment hits, and the direction its surface faces there.
  • A3D_GetSurfaceRotation: Find the rotation that stands an object on a surface, such as a crate on a slope.

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