The main difficulty is to built the objects/walls to not interfere with each other.
Here is a basic example (with some jerkiness):
cls
sync on
sync rate 60
phy start
autocam off
`roof and ground
make object box 1,400,2,400
position object 1,0,-1,0
make object box 2,100,2,100
position object 1,0,-1,0
position object 2,0,50,0
`wall 1 and 2
make object box 3,2,50,100
make object box 4,2,50,100
position object 3,49,25,0
position object 4,-49,25,0
`wall 3
make object box 5,100,50,2
position object 5,0,25,49
`wall 4
make object box 6,20,50,2
position object 6,-40,25,-49
make object box 7,60,50,2
position object 7,20,25,-49
make object box 8,20,15,2
position object 8,-20,42,-49
`door
make object box 9,20,35,0.5
position object 9,-20,17.2,-49
`color objects
color object 9,rgb(85,51,47)
for i = 1 to 8
color object i,rgb(255,232,255)
next i
color object 1,rgb(0,70,0)
`create rigid bodies
for i = 2 to 9
phy make rigid body dynamic box i
next i
phy make rigid body static box 1
`create joints
phy make fixed joint 1,1,3
phy make fixed joint 2,1,4
phy make fixed joint 3,1,5
phy make fixed joint 4,1,6
phy make fixed joint 5,1,7
phy make fixed joint 6,2,3
phy make fixed joint 7,2,4
phy make fixed joint 8,2,5
phy make fixed joint 9,2,8
phy make fixed joint 10,2,7
phy make fixed joint 11,3,5
phy make fixed joint 12,3,7
phy make fixed joint 13,4,5
phy make fixed joint 14,4,6
phy make fixed joint 15,5,3
phy make fixed joint 16,8,6
phy make fixed joint 17,8,7
phy make fixed joint 18,9,6
phy make fixed joint 19,9,8
phy make fixed joint 20,9,7
phy make fixed joint 21,9,1
`building the joints seems to not allow to delete joints properly
`for i = 1 to 21
`phy build fixed joint i
`next i
cam = 1
do
`destroy door
if returnkey() = 1 and retkey = 0 and door = 0
for i = 18 to 21
phy delete joint i
next i
PHY ADD RIGID BODY FORCE 9,0,0,50,15,5,0,2
door = 1
retkey = 1
endif
`destroy walls
if returnkey() = 1 and retkey = 0 and door = 1
for i = 1 to 17
phy delete joint i
next i
for i = 2 to 8
PHY ADD RIGID BODY FORCE i,0,0,10,2
next i
door = 2
retkey = 1
endif
if returnkey() = 0 and retkey = 1 then retkey = 0
`camera behaviour
if inkeY$() = "1" then cam = 1
if inkeY$() = "2"
cam = 2
msx# = 0
msy# = 0
endif
if cam = 1
position camera 0,0,6.87,-157.25
rotate camera 0,0,0,0
endif
if cam = 2
if mouseclick() = 1 then move camera 0,1
if mouseclick() = 2 then move camera 0,-1
msx# =(mousemovex()/8.0)+msx#
msy# =(mousemovey()/8.0)+msy#
yrotate camera 0,msx#
xrotate camera 0,msy#
endif
set cursor 0,0
print "Press returnkey once to destroy the door"
print "Press it a second time to destroy the walls"
print " "
print "1 fixed camera"
print "2 free camera"
phy update
sync
loop
I've encountered 2 problems in writing this example, namely that joints work even though you don't "build" them and actually, if you build them they don't work properly.
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why.
Programmers combine theory and practice: Nothing works and they don't know why.