PhysicsRate
How much time each UpdateWorld simulates, as steps a second.
PhysicsRate [steps_per_second]
Parameters
- steps_per_second (optional)
- defaults to 60
Description
Sets how much time each UpdateWorld simulates: one step of 1/steps_per_second seconds. The default of 60 suits a game that runs at 60 frames a second.
Physics moves at the same speed however fast the computer is, because each UpdateWorld always simulates the same time. For a game that updates 30 times a second, use PhysicsRate 30. The anim_speed# of UpdateWorld scales the step too, so UpdateWorld 0.5 is slow motion.
Using the frame tweening of CaptureWorld and RenderWorld with a fixed number of updates a second gives smooth physics at any frame rate.
Example
; Physics example (an ArcBasic extension); Bodies fall, tumble and come to rest. Space drops another, G changes gravityGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,6,-16TurnEntity camera,15,0,0light=CreateLight()RotateEntity light,50,30,0; static bodies never moveground=CreatePlane()EntityColor ground,80,140,80EntityPhysics ground,1ramp=CreateCube()ScaleEntity ramp,4,.2,3RotateEntity ramp,0,0,25PositionEntity ramp,-3,2,0EntityPhysics ramp,1EntityFriction ramp,.2PhysicsRate 60moon=FalseWhile Not KeyHit(1) If KeyHit(57) ; dynamic bodies are moved by the simulation If Rand(0,1) body=CreateCube() ScaleEntity body,.5,.5,.5 EntityPhysics body,2,2 Else body=CreateSphere(12) ScaleEntity body,.4,.4,.4 EntityPhysics body,2,1 EntityBounce body,.6 EntityDamping body,.05,.5 EndIf PositionEntity body,Rnd(-5,-2),8,Rnd(-1,1) TurnEntity body,Rnd(360),Rnd(360),0 EntityColor body,Rand(100,255),Rand(100,255),Rand(100,255) EntityMass body,1 EndIf If KeyHit(34) moon=Not moon If moon Then PhysicsGravity 0,-1.6,0 Else PhysicsGravity 0,-9.8,0 EndIf UpdateWorld RenderWorld Text 0,0,"Space: drop a body G: change gravity" If body Then Text 0,15,"Last body's physics mode: "+GetEntityPhysics(body) FlipWendEnd
