Blitz3D+ Command Reference

WorldPhysicsBody ( world,entity_id$,body_id$ )

Parameters

world - world handle

entity_id$ - ID of the entity carrying the physics component

body_id$ - local body ID in its .physics definition

Description

Returns the body created by an authored physics component, or 0.

Use it to grab a body from a loaded level - the swinging bridge plank you want to push, for instance. The result is 0 if the named body does not exist, and until the authored world is ready.

The handle is owned by the world and expires when FreeWorld releases it.

For the full story, see the reusable resources guide; the complete ReusablePhysics sample loads an authored physics world.

Requires Extended mode.

See also: WorldPhysicsContext, WorldPhysicsJoint, FreeWorld.

Example

; WorldPhysicsContext Example
; ---------------------------
; Requires Extended mode.

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

; Load the reusable-physics showcase: its .physics files author the bodies
scene=LoadWorldAsync("../../../samples/physics/physics-showcase.world")
While WorldReady(scene)=0
    If WorldLoadState(scene)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(scene)
    UpdateAsyncLoads 2
Wend
SetWorld scene

; The world owns its physics context; UpdateWorld does not step it
context=WorldPhysicsContext(scene)

; Look up authored bodies and joints by entity ID and local ID
falling=WorldPhysicsBody(scene,"falling","body")
hinge=WorldPhysicsJoint(scene,"hinge","pivot")
tether=WorldPhysicsJoint(scene,"tether","tether")

; Camera fixed on the showcase - the arrow keys turn it around its target
camera=FindWorldEntity(scene,"camera")
target=CreatePivot()
PositionEntity target,0,2,0
PointEntity camera,target
EntityParent camera,target

AmbientLight 115,125,140

timer=CreateTimer(60)

While Not KeyDown(1)

    ; Space kicks the authored falling body upwards
    If KeyHit(57) Then PhysicsBodyImpulse falling,0,6,0

    ; Left / right orbit the camera around the showcase
    If KeyDown(203) Then TurnEntity target,0,1,0
    If KeyDown(205) Then TurnEntity target,0,-1,0

    ; Step the world-owned context explicitly, at a fixed 60 Hz
    ticks=WaitTimer(timer)
    If ticks>6 Then ticks=6
    For tick=1 To ticks
        StepPhysics context,1.0/60.0,4
    Next

    RenderWorld

    ; Outline the bodies and joints so the authored assembly is visible
    PhysicsDebugDraw context,camera,9

    Text 0,0,"Left / Right: orbit camera   Space: kick the falling body   Esc: exit"
    Text 0,20,"WorldPhysicsContext(scene) = "+(context<>0)+"   (stepped here with StepPhysics)"
    Text 0,40,"WorldPhysicsBody(scene,"+Chr(34)+"falling"+Chr(34)+","+Chr(34)+"body"+Chr(34)+") height: "+EntityY(PhysicsBodyEntity(falling),True)
    Text 0,60,"WorldPhysicsJoint hinge angle: "+PhysicsJointAngle(hinge)+"   tether found: "+(tether<>0)

    Flip

Wend

FreeWorld scene

End

Index