EntityCapsule entity,radius#,height#

Parameters

entity - entity whose Box3D capsule collider is configured

radius# - positive radius around the local Y axis

height# - full end-to-end height; must be at least twice radius#

Description

Selects a Y-aligned capsule as an entity's collider in Box3D classic-collision mode.

Capsule colliders take effect in the Box3D backend, selected with SetCollisionBackend 1. Capsules are especially useful for walking characters: the cylindrical middle stays a consistent distance from walls while the rounded ends move smoothly over edges. The entity origin is at the capsule centre, and Box3D keeps the source upright by locking angular motion.

World X and Z scale must have equal magnitudes; they multiply the radius. World Y scale multiplies the full height. Invalid, non-finite, zero, or too-short dimensions stop with a runtime error before physics steps.

EntityCapsule replaces EntityRadius or EntityConvex as the source definition. It is also used as the destination collider for Collisions method 1 in Box3D mode; method 1 falls back to EntityRadius for destinations without an active capsule definition. Therefore two entities configured with EntityCapsule can use Collisions character_type,character_type,1,2 for capsule-to-capsule contact. Other destination methods still use their own EntityBox, polygon geometry, or EntityConvex data. Copies share the immutable definition and receive independent hidden bodies.


See also: EntityRadius, EntityConvex, Collisions, SetCollisionBackend.

Example

; EntityCapsule Example
; ---------------------

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

; Box3D classic-collision mode; capsules are its character collider
SetCollisionBackend 1

; Camera fixed on the arena - the arrow keys steer the character instead
camera=CreateCamera()
PositionEntity camera,0,4,-10

light=CreateLight()
RotateEntity light,55,-30,0

; A capsule-collided character: pivot source, visible capsule child of the same size
character=CreatePivot()
mesh=CreateCapsule(0.45,1.8,16,character)
EntityCapsule character,0.45,1.8
EntityType character,1
PositionEntity character,0,1.2,0

; A moving platform for the capsule to ride
platform=CreateCube()
ScaleEntity platform,2,0.25,2
EntityBox platform,-1,-1,-1,2,2,2
EntityType platform,2

Collisions 1,2,3,1
ResetEntity character

While Not KeyDown(1)

    ; The platform slides; grip response 3 carries the capsule with it
    PositionEntity platform,2*Sin(MilliSecs()*0.04),0,0

    ; Simple gravity plus left/right steering
    TranslateEntity character,0,-0.03,0
    If KeyDown(203) Then TranslateEntity character,-0.05,0,0
    If KeyDown(205) Then TranslateEntity character,0.05,0,0

    UpdateWorld

    ; Show the hidden Box3D colliders
    DebugEntityCollider character,0
    DebugEntityCollider platform,3

    RenderWorld

    Text 0,0,"Left/Right: move character   Esc: exit"
    Text 0,20,"EntityCapsule character,0.45,1.8 riding a moving platform"

    Flip

Wend

End

Index