Blitz3D+ Command Reference

PhysicsWorldGetMaxSpeed# ( world )

Parameters

world - live explicit physics world

Description

Returns the authored maximum linear speed in m/s, as a Float.

The default is 400. This reports a policy value, not a measurement of body motion or contact speed.

Caps native integrated linear-velocity magnitude while preserving its direction. Lowering the limit does not immediately rewrite an authored body velocity; the cap is enforced when the solver integrates a subsequent step. It does not cap angular speed. Kinematic entities retain the existing entity-target driving contract.

Reading this value does not change simulation state.

Ordinary world/body arguments must be live handles of the correct kind; invalid or stale handles raise a runtime error. Mutations are rejected while the owning world is stepping.

Requires Extended mode.

See also: PhysicsWorldMaxSpeed, PhysicsWorldGetHitThreshold, PhysicsWorldGetRestitutionThreshold, PhysicsWorldGetContactRecycleDistance.

Example

; PhysicsWorldGetMaxSpeed Example
; -------------------------------
; Requires Extended mode.

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

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,7,2,-1
RotateEntity camera,5,80,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 thin glass pane, only 4 cm thick
pane=CreateCube()
ScaleEntity pane,1.5,1.5,0.02
PositionEntity pane,0,1.5,0
EntityColor pane,150,220,255
EntityAlpha pane,0.6
pane_body=CreatePhysicsBody(world,pane,PHYSICS_STATIC)
pane_shape=PhysicsBodyBox(pane_body,3,3,0.04)

; A small ball that ignores gravity
ball=CreateSphere(8)
ScaleEntity ball,0.1,0.1,0.1
EntityColor ball,255,120,70
ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC)
ball_shape=PhysicsBodySphere(ball_body,0.2)
PhysicsBodyGravityScale ball_body,0
ResetPhysicsBody ball_body,0,1.5,-4,0,0,0

limit#=400

While Not KeyDown(1)

    ; Space fires the ball at the pane at 100 m/s
    If KeyHit(57)
        ResetPhysicsBody ball_body,0,1.5,-4,0,0,0
        PhysicsBodyVelocity ball_body,0,0,100
    EndIf

    ; [ and ] lower or raise the world's speed limit
    If KeyHit(26) And limit>5 Then limit=limit-5
    If KeyHit(27) Then limit=limit+5
    PhysicsWorldMaxSpeed world,limit
    StepPhysics world,1.0/60.0,4

    ; 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

    Text 0,0,"Arrow keys: move camera   Space: fire   [ / ]: speed limit   Esc: exit"
    Text 0,20,"PhysicsWorldGetMaxSpeed(world) = "+PhysicsWorldGetMaxSpeed(world)+" m/s"
    Text 0,40,"Ball speed: "+PhysicsBodyVelocityZ(ball_body)+" m/s"

    Flip

Wend

FreePhysicsWorld world
End

Index