; PhysicsQueryMoveFraction Example ; -------------------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,5,-10 RotateEntity camera,25,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) ; Scenery: a wall, a low step and a ramp wall=CreateCube() ScaleEntity wall,0.2,1,2 PositionEntity wall,3,1,0 wall_body=CreatePhysicsBody(world,wall,PHYSICS_STATIC) wall_shape=PhysicsBodyBox(wall_body,0.4,2,4) stair=CreateCube() ScaleEntity stair,1,0.15,1 PositionEntity stair,-2,0.15,2 stair_body=CreatePhysicsBody(world,stair,PHYSICS_STATIC) stair_shape=PhysicsBodyBox(stair_body,2,0.3,2) ramp=CreateCube() ScaleEntity ramp,1.5,0.1,1 RotateEntity ramp,0,0,20 PositionEntity ramp,-2,0.4,-2 ramp_body=CreatePhysicsBody(world,ramp,PHYSICS_STATIC) ramp_shape=PhysicsBodyBox(ramp_body,3,0.2,2) ; The character is an ordinary entity moved by capsule queries, not a body character=CreateCylinder(12) ScaleEntity character,0.3,0.9,0.3 PositionEntity character,0,1,0 EntityColor character,255,230,60 query=CreatePhysicsQuery(world) vy#=0 While Not KeyDown(1) ; A / D / W / S walk, Space jumps when standing on something vx#=(KeyDown(32)-KeyDown(30))*3 vz#=(KeyDown(17)-KeyDown(31))*3 If KeyHit(57) And Abs(vy)<0.01 Then vy=5 vy=vy-10.0/60.0 ; Move a 0.6 m wide, 1.8 m tall capsule; it slides along what it hits fraction#=MovePhysicsCharacter(query,character,0.6,1.8,vx/60,vy/60,vz/60) ; Remove the part of the velocity that pushes into what it hit, ; so landing stops the fall and walls stop the walk ClipPhysicsCharacterVelocity query,vx,vy,vz vy=PhysicsQueryMoveVelocityY(query) 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 A / D / W / S: walk Space: jump Esc: exit" Text 0,20,"PhysicsQueryMoveFraction(query) = "+PhysicsQueryMoveFraction(query) Text 0,40,"(solved move "+PhysicsQueryMoveSolvedX(query)+", "+PhysicsQueryMoveSolvedY(query)+", "+PhysicsQueryMoveSolvedZ(query)+")" Flip Wend FreePhysicsWorld world End