PhysX for DarkBASIC Professional

Example 1 : Character Controller Demo

In the Character Controller example we have loaded in a level (built with FPS Creator). From there you can walk and look around, with full sliding collision on all objects.

` this program shows how to load an FPS Creator level
` and walk around it using the character controller

` set up general properties
sync on
sync rate 60
autocam off
phy start
set camera range 0.5, 30000
hide mouse

` move into the media directory
set dir "media"

` load the level and make a static mesh for it
load object "universe.dbo", 1
set object light 1, 0
phy make rigid body static mesh 1

` load our skybox
load object "skybox2.x", 2
set object light 2, 0
set object texture 2, 3, 1
scale object 2, 30000, 30000, 30000

` come out of the media directory
set dir ".."

` create our box controller
make object box 3, 20, 50, 20
phy make box character controller 3, 434, 42, -517, 10, 35, 10, 1, 10.5, 45.0
hide object 3

` display Dark Physics logo
load image "logo.png", 100000
sprite 1, 0, 600 - 60, 100000

` our main loop
do
   ` display instructions
   set cursor 0, 0
   print "Using Dark Physics for collision detection of an FPS Creator level"
   print "Use the arrow keys and mouse to move around"

   ` rotate and position the camera based on the box controller
   position camera object position x ( 3 ), object position y ( 3 ) + 20, object position z ( 3 )
   rotate camera object angle x ( 3 ), object angle y ( 3 ), object angle z ( 3 )

   OldCamAngleY# = CameraAngleY#
   OldCamAngleX# = CameraAngleX#

   CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
   CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )

   yrotate object 3, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
   xrotate object 3, curveangle ( CameraAngleX#, OldCamAngleX#, 24 )

   ` react to key presses and move the controller
   key = 0

   if upkey ( )
      key = 1
      phy move character controller 3, 200.0
   endif

   if downkey ( )
      key = 1
      phy move character controller 3, -200.0
   endif

   if key = 0
      phy move character controller 3, 0.0
   endif

   ` update the simulation and screen
   phy update
   sync
loop

Return to the Examples List

Dark Physics Atari forever :)

© Copyright 2006 The Game Creators Ltd. All Rights Reserved.
PhysX and associated imagery are trade marks of Aegia Technologies Inc, used with permission.