here is a sample you can pull apart it assumes all matrices are the same size for it to work correctly
rem ------------------------------------------
rem traversing multiple environments
rem indi may 2003
rem tutor DR.AV feb 2000
rem -------------------------------------------
sync rate 60 : sync on : hide mouse
set text font "verdana"
set text size 16
set text opaque
ink rgb(255,255,255),1
x#=500
z#=500
y#=500
cms# = 28.0
cts# = 3.5
Min = 0
Max = 0
Occupied = 1
camdist = 550
camhgt = 380
mtxsiz# = 5000.0
maxmtx = 3
make matrix 1,mtxsiz#,mtxsiz#,20,20
position matrix 1,0,0,0
randomize matrix 1,80
Update Matrix 1
make matrix 2,mtxsiz#,mtxsiz#,20,20
position matrix 2,5000,0,0
randomize matrix 2,80
Update Matrix 2
make matrix 3,mtxsiz#,mtxsiz#,20,20
position matrix 3,10000,0,0
randomize matrix 3,80
Update Matrix 3
make object cube 1,100
do
if upkey()=1 then x#=newxvalue(x#,a#,cms#) : z#=newzvalue(z#,a#,cms#)
if downkey()=1 then x#=newxvalue(x#,a#,-18.0) : z#=newzvalue(z#,a#,-18.0)
if leftkey()=1 then a#=wrapvalue(a#-cts#)
if rightkey()=1 then a#=wrapvalue(a#+cts#)
if inkey$()="1" then inc camhgt
if inkey$()="2" then dec camhgt
if inkey$()="3" then inc camdist
if inkey$()="4" then dec camdist
if inkey$()="5" then inc camalt
if inkey$()="6" then dec camalt
for i = 1 to maxmtx
Min = Matrix Position x(i)
Max = Matrix Position x(i) + mtxsiz#
if x# >= Min AND x# <= Max
Min = Matrix Position z(i)
Max = Matrix Position z(i) + mtxsiz#
if z# >= Min AND z# <= Max
Occupied = i
Min = 0
Max = 0
i = maxmtx
endif
endif
next i
if Occupied < 1
Occupied = 1
endif
y#=get ground height(Occupied,x# - Matrix Position x(Occupied),z# - Matrix Position z(Occupied))
position object 1,x#,y#,z#
rotate object 1,0.0,a#,0.0
cx#=newxvalue(x#,wrapvalue(a#+180),camdist)
cz#=newzvalue(z#,wrapvalue(a#+180),camdist)
cy#=get ground height(Occupied,x# - Matrix Position x(Occupied),z# - Matrix Position z(Occupied))
position camera cx#,cy# + camhgt,cz#
point camera x#,y#,z#
text 10,10,"x: "+STR$(x#)
text 10,30,"y: "+STR$(y#)
text 10,50,"z: "+STR$(z#)
text 10,70,"camdist :"+STR$(camdist)
text 10,90,"camhgt :"+STR$(camhgt)
text 10,130,"Occupied = "+STR$(Occupied)
sync
loop