There's a demo in the darkphysics examples folder that shows you how to do it. Here is the code from it:
sync on
sync rate 60
autocam off
set camera range 1,1000
set normalization on
hide mouse
global jointID as integer : jointID = 0
global zoom# as double float : zoom# = -30
global ammoID as integer
global mtimer as integer
phy start
phy set gravity 0, -2, 0
load image "stripe5.png",1000
make object sphere 1000,400,48,48
texture object 1000,1000
scale object texture 1000,6,6
set object cull 1000,0
rotate object 1000,0,0,90
load image "stripe6.png", 3
id = 1
id = makeLevel(id)
texture object 1, 3
id = 100
id = createRagDoll(id,0,11,0)
ammoID = 5000
null = mousemovex()
null = mousemovey()
make light 1
set directional light 1, -5,-5,5
position camera 0,10,-30
y = 20
position camera 0, 10, -100
position camera -60, 35, -74
rotate camera 28, 38, 0
load image "logo.png", 100000
sprite 1, 0, 600 - 60, 100000
do
rotate object 1000, 0, object angle y( 1000 ) - 0.3, 0
if rnd( 50 ) = 25
stimer = timer()+3000
a = rnd( 5 )
if a = 0
id = createRagDoll(id,-30,40,-20)
endif
if a = 1
id = createRagDoll(id,-30,40,20)
endif
if a = 2
id = createRagDoll(id,30,40,20)
endif
if a = 3
id = createRagDoll(id,30,40,-20)
endif
if a = 4
id = createRagDoll(id,0,40,0)
endif
y = y + 20
if y > 150
y = 40
endif
endif
phy update
sync
loop
function controlCamera()
endfunction
information:
` show some information
` start printing at top of screen
set cursor 0, 0
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
print ""
` current camera position
print ""
print "x = " + str$ ( camera position x ( ) )
print "y = " + str$ ( camera position y ( ) )
print "z = " + str$ ( camera position z ( ) )
print ""
print ""
print "x = " + str$ ( camera angle x ( ) )
print "y = " + str$ ( camera angle y ( ) )
print "z = " + str$ ( camera angle z ( ) )
print ""
return
userInput:
` simple mouse and keyboard movement
` move around with arrow keys
control camera using arrowkeys 0, g_fSpeed#, g_fTurn#
` store old camera angle
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
` store new camera angle
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
` rotate camera
yrotate camera curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate camera curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
` speed up movement
if inkey$ ( ) = "+"
if g_fSpeed# < 1000
g_fSpeed# = g_fSpeed# + 0.01
endif
endif
` slow down movement
if inkey$ ( ) = "-"
if g_fSpeed# > 0.002
g_fSpeed# = g_fSpeed# - 0.001
endif
endif
position mouse 400, 300
return
function controlShooting()
if mouseclick()=1 and mtimer<timer()
mtimer = timer()+300
angy# = camera angle y()
angx# = -camera angle X()
make object sphere ammoID,1
position object ammoID,camera position x(),camera position y(),camera position z()
color object ammoID, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular ammoID, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power ammoID, 255
set object ambient ammoID,0
inc ammoID
endif
endfunction
function makeLevel(id)
make object box id,100,1,100
color object id,rgb(100,100,100)
position object id,0,-10,0
phy make rigid body static box id
inc id
make object box id,10,1,15
position object id,-30,10,-20
phy make rigid body static box id
texture object id, 3
inc id
make object box id,10,1,15
position object id,-30,15,20
phy make rigid body static box id
texture object id, 3
inc id
make object box id,10,1,15
position object id,30,15,20
phy make rigid body static box id
texture object id, 3
inc id
make object box id,10,1,15
position object id,30,10,-20
phy make rigid body static box id
texture object id, 3
inc id
make object box id,5,1,5
position object id,0,10,0
phy make rigid body static box id
texture object id, 3
inc id
endfunction id
function createRagDoll(id,x, y, z)
firstID = ID
rem torso
makeObjectCapsule(id,4,2.6)
scale object id,100,70,100
position object id,0+x,11+y,0+z
phy make rigid body dynamic box id
body = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem lower torso
makeObjectCapsule(id,4,2.55)
scale object id,100,70,100
position object id,0+x,9.5+y,0+z
phy make rigid body dynamic box id
Lbody = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem head
headID = id
makeObjectCapsule(id,2,1.5)
position object id,0+x,14+y,0+z
phy make rigid body dynamic box id
head = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem left upper arm
makeObjectCapsule(id,2,0.85)
zrotate object id,90
position object id,2.75+x,12+y,0+z
phy make rigid body dynamic box id
leftUarm = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem left lower arm
makeObjectCapsule(id,2,0.85)
zrotate object id,90
position object id,5.5+x,12+y,0+z
phy make rigid body dynamic box id
leftLarm = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem right upper arm
makeObjectCapsule(id,2,0.85)
zrotate object id,90
position object id,-2.75+x,12+y,0+z
phy make rigid body dynamic box id
rightUarm = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem right lower arm
makeObjectCapsule(id,2,0.85)
zrotate object id,90
position object id,-5.5+x,12+y,0+z
phy make rigid body dynamic box id
rightLarm = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem left upper leg
makeObjectCapsule(id,2.5,1.2)
position object id,0.75+x,6+y,0+z
phy make rigid body dynamic box id
leftUleg = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem left lower leg
makeObjectCapsule(id,2.5,1)
position object id,0.75+x,3+y,0+z
phy make rigid body dynamic box id
leftLleg = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem right upper leg
makeObjectCapsule(id,2.5,1.2)
position object id,-0.75+x,6+y,0+z
phy make rigid body dynamic box id
rightUleg = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
rem right lower leg
makeObjectCapsule(id,2.5,1)
position object id,-0.75+x,3+y,0+z
phy make rigid body dynamic box id
rightLleg = id
color object id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular id, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power id, 255
set object ambient id,0
inc id
strength = 150
i=jointID
rem join the limbs together - ball and sockets
phy make sphere joint i,body,leftUarm,1.5+x,12 + y,0+z
phy make sphere joint i+1,body,rightUarm,-1.5+x,12 + y,0+z
phy make sphere joint i+2,Lbody,leftUleg,0.75+x,7.5 + y,0+z
phy make sphere joint i+3,Lbody,rightUleg,-0.75+x,7.5 + y,0+z
rem elbows and knees
phy make revolute joint i+4,leftUarm,leftLarm, 0, 1, 0, 4+x,12 + y,0+z
phy make revolute joint i+5,rightUarm,rightLarm, 0, 1, 0, -4+x,12 + y,0+z
phy make revolute joint i+6,leftUleg,leftLleg, 1, 0, 0, 0.75+x,4.6 + y,0+z
phy make revolute joint i+7,rightUleg,rightLleg, 1, 0,0,-0.75+x,4.6 + y,0+z
rem head and body
phy make revolute joint i+8,body,head, 1, 0,0,0+x,13 + y,0+z
phy make revolute joint i+9,body,Lbody, 1,0,0,0+x,10.3 + y,0+z
rem future update - add limit joints to restrict movement
rem - add motors?
inc jointID,10
endfunction id
function makeObjectCapsule(obj, h#, r#)
h# = h# - r#
if h#<0 then exitfunction
rem rows must be odd
rows = 11
cols = 16
make object sphere obj,r#,rows,cols
lock vertexdata for limb obj,0,1
for i=0 to get VertexData Vertex Count()
x#=get VertexData Position X(i)
y#=get VertexData Position Y(i)
z#=get VertexData Position Z(i)
if y#>0
set VertexData Position i,x#,y#+h#,z#
else
set VertexData Position i,x#,y#-h#,z#
endif
next i
unlock vertexdata
` calculate collision bounds
make mesh from object 1,obj
delete object obj
make object obj,1,0
delete mesh 1
endfunction
function strapline(mode,s$)
if mode=0
ink 0x88FFFFFF,0 : set text font "Tahoma" : set text size 32
else
center text screen width()/2,20,s$
endif
endfunction
Your signature has been erased by a mod becuase it doesnt conform to 600 x 120 in size