QueryPhysicsCapsuleCast ( query,ax#,ay#,az#,bx#,by#,bz#,diameter#,dx#,dy#,dz#[,all_hits] )

Parameters

query - query handle

ax# - world-space endpoint A X
ay# - world-space endpoint A Y
az# - world-space endpoint A Z

bx# - world-space endpoint B X
by# - world-space endpoint B Y
bz# - world-space endpoint B Z

diameter# - positive finite diameter, in metres

dx# - world X translation, end minus start
dy# - world Y translation, end minus start
dz# - world Z translation, end minus start

all_hits (optional) - True for one nearest hit per eligible owning shape; False for only the closest hit (optional; 0) (default)

Description

Sweeps a capsule through the world and records what it hits.

Sweeps a capsule whose segment endpoints A and B are world-space sphere centres, with a positive finite diameter in metres. The total length includes one diameter beyond the segment; coincident endpoints form a sphere. Orientation stays fixed during translation.

The translation is end minus start, not an endpoint or velocity. It must be finite, non-zero and representable. all_hits=False returns the closest eligible hit; True returns the nearest intersection with each eligible owning shape, not every triangle, compound child, entry and exit within a shape. Results sort by increasing fraction, then wrapper shape handle, child and triangle indices. Native zero-fraction hits are ignored, matching the legacy closest-ray convention. Use an explicit overlap query to find starting intersections. Mesh/terrain shapes are triangle surfaces, not filled volumes.

Queries use two-sided category/mask filtering in the existing 32-bit domain, plus optional ignored-body, sensor and target rules. Collision groups and joints do not override query masks. Disabled bodies are absent from world queries. Existing shape filters default to all category bits; assign explicit shape categories when separating groups.

Results are copied. They survive StepPhysics and other queries until this query runs successfully again or is freed. Failed runs preserve the previous results. Freeing the owning world frees its queries. Invalid/stale/wrong-kind handles and invalid hit indices raise runtime errors.


See also: CreatePhysicsQuery, PhysicsQueryFilter, PhysicsQueryTarget, QueryPhysicsRay, QueryPhysicsSphere, PhysicsQueryLimit.

Example

; QueryPhysicsCapsuleCast Example
; -------------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,7,-8
RotateEntity camera,40,0,0

light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 60,60,60

; An independent Box3D world with standard gravity
world=CreatePhysicsWorld()

; Blue static floor
ground=CreateCube()
ScaleEntity ground,6,0.5,6
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,12,1,12)

; A ring of crates to aim at
For i=1 To 8
    crate=CreateCube()
    ScaleEntity crate,0.5,0.5,0.5
    PositionEntity crate,Cos(i*45)*4,0.5,Sin(i*45)*4
    EntityColor crate,255,120,70
    crate_body=CreatePhysicsBody(world,crate,PHYSICS_STATIC)
    crate_shape=PhysicsBodyBox(crate_body,1,1,1)
Next

; A query object runs searches and keeps a copy of their results
query=CreatePhysicsQuery(world)

; Start aimed at a crate
angle#=45

While Not KeyDown(1)

    ; A and D sweep the ray around the centre
    If KeyDown(30) Then angle=angle+1.5
    If KeyDown(32) Then angle=angle-1.5
    dx#=Cos(angle)*6
    dz#=Sin(angle)*6

    StepPhysics world,1.0/60.0,4

    ; Sweep an upright capsule, like a character walking out from the centre
    hits=QueryPhysicsCapsuleCast(query,0,0.3,0,0,1.2,0,0.4,dx,0,dz)

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    ; Draw the ray from the centre to the first hit, or to its full length
    CameraProject camera,0,0.5,0
    start_x=ProjectedX()
    start_y=ProjectedY()
    If hits>0
        CameraProject camera,PhysicsQueryX(query,1),PhysicsQueryY(query,1),PhysicsQueryZ(query,1)
    Else
        CameraProject camera,dx,0.5,dz
    EndIf
    Line start_x,start_y,ProjectedX(),ProjectedY()

    Text 0,0,"Arrow keys: move camera   A / D: sweep the ray   Esc: exit"
    Text 0,20,"QueryPhysicsCapsuleCast(query,...) = "+hits
    Text 0,40,"(a 0.4 m capsule from 0.3 m to 1.2 m above the floor)"

    Flip

Wend

FreePhysicsWorld world
End

Index