This shows user control of a kinematic object linked to dynamic objects, joints and a use for creating joints on the fly:
When the sphere at the end of the rope touches the box on the floor you can press and hold W to attach to it (using a fixed joint) then use the cursor keys and Q and A to drag the box to another location. Pressing W again to release it.
Rem Project: JW physics test 01
Rem Created: 02/09/2006 17:23:01
Rem ***** Main Source File *****
` set up the program
sync on
sync rate 60
randomize timer ( )
set display mode 800,600,32
set window on
phy start
phy make material 1, "floor"
phy set material restitution 1, 0.05
phy set material dynamic friction 1, 0.9
phy build material 1
make object box 1,250,1,250
position object 1,0,-20,0
phy make rigid body static box 1,1
rem Create vehicle physics body
width# = 0.75
height# = 0.4
length# = 2.2
wheelX# = 1.1
wheelY# = 0.3
wheelZ# = 1.5
radius# = 0.6
wheelHeight# = 0.2
autocam off
position camera -20,20,-25
point camera 0,10,0
make light 1
set directional light 1, -5,-5,5
phy set gravity 0.0, -25, 0.0
` make the floor
` create dynamic box
phy make material 2, "box"
phy set material restitution 2, 0.05
phy set material dynamic friction 2, 0.9
phy build material 2
make object box 2,5,5,5
position object 2,10,24,10
phy make rigid body dynamic box 2 `build box and apply material
phy set rigid body mass 2,500
` create third dynamic box and make this one kinematic
make object box 3,5,5,5
position object 3,0,6,0
phy make rigid body dynamic box 3
phy set rigid body kinematic 3, 1
` attachment point for cloth
make object box 50, 6, 1, 1
position object 50, 0, 10, 20
phy make rigid body static box 50
` create our cloth
phy make cloth 200
phy set cloth dimensions 200, 5, 13, 0.2
phy set cloth position 200, 2.5, 10, 20
phy set cloth rotation 200, 135, 0, -180
phy set cloth friction 200, 0.5
phy set cloth tearing 200, 1
phy set cloth tear factor 200, 2.2
phy set cloth bending 200, 1
phy set cloth two way collision 200, 1
phy build cloth 200
phy attach cloth to shape 200, 50, 0
` we use this command to link the timing to the frame rate
phy set auto fixed timing
` colour all of our objects
for i = 1 to 3
if object exist ( i )
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular power i, 255
set object ambient i,0
endif
next i
`this makes a rope!
y#=2.5
for i = 4 to 10
make object box i,0.2,2,0.2
position object i, 0, Y#, 0
phy make rigid body dynamic sphere i
phy set rigid body linear damping i, 2 `this plus the reduced mass of objects to be picked up prevents the
`links from going crazy!
phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i )+1, object position z ( i )
phy set sphere joint swing limit i, 2.0, 0.1,0.2
phy set sphere joint twist limit i, 0.1, 0.5
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object specular i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
set object ambient i, 255
set object specular power i, 255
Y# = Y# - 2
next i
`this adds a little doobry on the bottom!
make object sphere 11,3
position object 11,0,y#,0
color object 11, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
phy make rigid body dynamic sphere 11
phy make sphere joint 11, 11, 10, object position x ( 11 ), object position y ( 11 )+1, object position z ( 11 )
phy set sphere joint swing limit 11, 35.0, 0.5,0.5
phy set sphere joint twist limit 11, 0.1, 0.5
` some variables we use in the main loop
captured=0
x# = 0
y# = 6
z# = 0
` main program loop
do
WHILE phy get collision data ( )=1
col_obj_a = phy get collision object a ( ): col_obj_b = phy get collision object b ( )
colA_x# = object position x (col_obj_a):colA_y# = object position y (col_obj_a):colA_z# = object position z (col_obj_a)
ENDWHILE
`if col1=1 then col_obj_a = phy get collision object a ( ): col_obj_b = phy get collision object b ( )
text 0,0,"KINEMATIC OBJECT CONTROL"
text 0,10,"Use Arrow keys and 'Q' & 'A' to move Kinematic object"
text 0,20,str$(scancode())
text 0,30,"Hold down 'W' to use the magnet and drop the box with 'E'"
text 0,40,"collision:"+str$(coll)
text 0,50,"Object A:"+str$(col_obj_a)+" Object B:"+str$(col_obj_b)
yesno=OBJECT COLLISION(11, 2)
if yesno=1 then text 0,50,"HIT!"
if leftkey()=1 then x#=x#-0.1
if rightkey()=1 then x#=x#+0.1
if upkey()=1 then y#=y#+0.1
if downkey()=1 then y#=y#-0.1
if keystate(16)=1 then z#=z#+0.1
if keystate(30)=1 then z#=z#-0.1
if keystate(17)=1 and yesno=1 and captured=0 then phy make fixed joint 15,2,11: captured=1
if keystate(18)=1 and captured=1 then phy delete joint 15: captured=0
` control the position of the kinematic object
phy set rigid body kinematic position 3, x#, y#, z#
point camera x#,y#,z#
phy update
sync
loop
BLACKMESA:SOURCE - mod for HL2 - Texture Artist
BIRTHSTAR:FRONTLINE - Texture & Environment Artist