I realize that TGC may have been on a tight schedule to put out Dark Physics, and I'd like to point out some problems with the "dark physics manual" .chm help file that is distributed:
Many of the programs don't work. They weren't even tested prior to publishing.
Take this example code from the Tutorials/Advanced Machinery section:
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
load image “metal1.tga”, 1
texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
load image “stripes5.png”, 100
texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ) )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack ( start, end, x, z )
y = 1
for i = start to end
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
The first thing noticable is that when pasting from the help file, everything gets double-spaced, so let's fix that:
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
load image “metal1.tga”, 1
texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
load image “stripes5.png”, 100
texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack ( start, end, x, z )
y = 1
for i = start to end
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Ok, with the spaces gone, let's try and run it.
"DarkBASIC professional Editor" - User function declaration must use no spaces, no numerical first character and include a set of brackets at line 49."
Hmm, already an error, let's fix that then by taking out the space between the function name and the open paranthesis (parenthesis are not brackets by the way, parenthesis=(), brackets=[]):
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
load image “metal1.tga”, 1
texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
load image “stripes5.png”, 100
texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, end, x, z )
y = 1
for i = start to end
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Now we might also notice that "end" used in the function's parameter list is highlighted in the editor as a keyword. We shouldn't be using DBP keywords as variable names, so let's fix that:
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
load image “metal1.tga”, 1
texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
load image “stripes5.png”, 100
texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Ok, let's try running it again.
"DarkBASIC Professional Editor" - Could not determine parameter type of "metal1.tga" at line 6.
Hmm, it looks like the " character used in the .chm file is not the same " character used in the editor, so we'll change all occurances of the rogue " to the right ". Oh, and there's a special close qoute character being used, gotta replace those too.
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
load image "metal1.tga", 1
texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
load image "stripes5.png”, 100
texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Ok, before we try again, we can go ahead and see that we're going to have problems loading the images referenced in the program, so let's go ahead and comment those lines out.
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera –30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i – 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Let's try running it again.
"DarkBASIC Professional Editor" - Could not determine parameter type of '-30' at line 27.
Weird, looks like the - character in the help file is not the same - character the editor uses, let's replace all the rogue -'s with the right -'s.
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 )
phy make rigid body dynamic sphere i
phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Try and run again.
"DarkBASIC Professional Editor" - Parameter mismatch in command 'PHY MAKE SPHERE JOINT' at line 35.
Hmm, the line looks ok, but let's retype it b/c we now that the help file characters are not friendly with the DBP editor.
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack ( 20, 35, 0, 17 )
CreateCubeStack ( 35, 50, 0, -15 )
CreateCubeStack ( 50, 65, -15, 10 )
CreateCubeStack ( 65, 80, -10, -8 )
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Try and run again.
"DarkBASIC Professional Editor" - Could not understand command at line 39.
That line certainly does look odd, let's retype those 4 lines and make them compatible with the editor.
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack(20,35,0,17)
CreateCubeStack(35,50,0,-15)
CreateCubeStack(50,65,-15,10)
CreateCubeStack(65,80,-10,-8)
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack( start, endt, x, z )
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Try and run again.
Ok, now we've ruled out all the problems with the editor, but we're getting runtime errors now:
"Error" - Runtime Error 7007 - Object already exists at line 53
Now we get to the real trouble with this code, it was never tested and the program is trying to make objects that have already been created.
The problem starts on this line:
CreateCubeStack(20,35,0,17)
You'll notice that object 20 has already been created in the program just before that line:
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
Ok, so let's go through the code and try to guess what the author was trying to do and get rid of duplicate object numbers:
phy start
sync on
sync rate 0
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack(21,35,0,17)
CreateCubeStack(36,50,0,-15)
CreateCubeStack(51,65,-15,10)
CreateCubeStack(66,80,-10,-8)
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack(start,endt,x,z)
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Let's run it and see what we get.
Ok that looks like a view of the scene from underneath the platform. Did the author forget to turn off the autocam? Yes. Let's put that in now.
phy start
sync on
sync rate 0
autocam off
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack(21,35,0,17)
CreateCubeStack(36,50,0,-15)
CreateCubeStack(51,65,-15,10)
CreateCubeStack(66,80,-10,-8)
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack(start,endt,x,z)
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Let's run and see what we get.
The program is running at warp 9 captain! Let's change the sync rate from 0 to 30 so we can see what's going on.
phy start
sync on
sync rate 30
autocam off
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack(21,35,0,17)
CreateCubeStack(36,50,0,-15)
CreateCubeStack(51,65,-15,10)
CreateCubeStack(66,80,-10,-8)
y# = -1
do
phy set rigid body angular velocity 4, 0, y#, 0
y# = y# + 1
phy update
sync
loop
function CreateCubeStack(start,endt,x,z)
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
Run again. Now we see that something is very wrong with the chain of balls hanging from the tower, it starts out fine, but after a couple hundred frames the balls seem to get disconnected and appear at random positions that are generally in the area they should be in, so let's try tweaking some parameters to try and slow down the velocity:
phy start
sync on
sync rate 30
autocam off
make object box 1, 40, 1, 40
position object 1, 0, 0, 0
`load image "metal1.tga", 1
`texture object 1, 1
phy make rigid body static box 1
make object sphere 100, 80
set object cull 100, 0
`load image "stripes5.png”, 100
`texture object 100, 100
make object box 2, 4, 16, 4
position object 2, 0, 9, 0
texture object 2, 1
phy make rigid body static box 2
make object box 3, 2, 2, 2
position object 3, 0, 18, 0
texture object 3, 1
phy make rigid body dynamic box 3
phy make revolute joint 1, 2, 3, 0, 1, 0, 0, 18, 0
make object box 4, 10, 1, 1
position object 4, 6, 18, 0
texture object 4, 1
phy make rigid body dynamic box 4
phy make revolute joint 3, 2, 4, 0, 1, 0, 0, 18, 0
position camera -30, 25, 0
rotate camera 40, 90, 0
Y# = 17
for i = 5 to 20
make object sphere i, 1
position object i, 10, Y#, 0
color object i, rgb ( rnd ( 255 ), rnd ( 255 ), rnd ( 255 ))
phy make rigid body dynamic sphere i
`phy make sphere joint i, i, i - 1, object position x ( i ), object position y ( i ), object position z ( i ), 100
phy make sphere joint i,i,i-1,object position x(i),object position y(i),object position z(i)
Y# = Y# - 1
next I
CreateCubeStack(21,35,0,17)
CreateCubeStack(36,50,0,-15)
CreateCubeStack(51,65,-15,10)
CreateCubeStack(66,80,-10,-8)
y# = -0.5
do
phy set rigid body angular velocity 4, 0, y#, 0
`y# = y# + 1
phy update
sync
loop
function CreateCubeStack(start,endt,x,z)
y = 1
for i = start to endt
make object cube i, 1
position object i, x, y, z
phy make rigid body dynamic box i
texture object i, 2
y = y + 1
next i
endfunction
We've taken out the incrementing of the value every loop, and just set it to a constant value. Everything seems to be fine now, except one of the box stacks seems to fall on its own.
Other example programs in the documentation have similar problems (not including the text export problems).
Please test example code before releasing it to the public, it's frustrating having to debug other's code, especially when the code is supposed to be illustrating how to do something you've never done before.