Try code below. It's a bit of a mess and has lots of duplicate code but is needed to optimise. Tried to post it last night but forum was down late last night!
It 'should' cope with matrix positioned anywhere and camera positioned anywhere. If matrix is always gonna positioned at 0,0,0 you can get rid of a lot of code.
sync on : sync rate 0 : autocam off
mat_x#=500 : mat_y#=2000 : mat_z#=200
mat_size_x=1000 : mat_size_z=1000
mat_tiles_x=32 : mat_tiles_z=32
make matrix 1,mat_size_x,mat_size_z,mat_tiles_x,mat_tiles_z
position matrix 1,mat_x#,mat_y#,mat_z#
randomize matrix 1,10
update matrix 1
position camera mat_x#-50,mat_y#+100,mat_z#-50
point camera mat_x#+50,mat_y#,mat_z#+50
do
gosub mousetile
if tx > -1
text 0,0,"X = "+str$(tx)+", Z = "+str$(tz)
endif
sync
loop
mousetile:
tx=-1 : ty=-1 : t=0
for f=0 to 5000 step 100
pick screen mousex(),mousey(),f
x#=get pick vector x()+camera position x() : y#=get pick vector y()+camera position y() : z#=get pick vector z()+camera position z()
if x# > mat_x# and x# < (mat_size_x + mat_x#) and z# > mat_z# and z# < (mat_size_z + mat_z#)
h#=get ground height(1,x#-mat_x#,z#-mat_z#) : v#=y#-h#-mat_y# : if v# < 0 then t=1 : exit
endif
next f
if t=1
t=0
for g=f-100 to f step 10
pick screen mousex(),mousey(),g
x#=get pick vector x()+camera position x() : y#=get pick vector y()+camera position y() : z#=get pick vector z()+camera position z() :
if x# > mat_x# and x# < (mat_size_x + mat_x#) and z# > mat_z# and z# < (mat_size_z + mat_z#)
h#=get ground height(1,x#-mat_x#,z#-mat_z#) : v#=y#-h#-mat_y# : if v# < 0 then t=1 : exit
endif
next g
if t=1
t=0
for h=g to g-10 step -1
pick screen mousex(),mousey(),h
x#=get pick vector x()+camera position x() : y#=get pick vector y()+camera position y() : z#=get pick vector z()+camera position z() :
if x# > mat_x# and x# < (mat_size_x + mat_x#) and z# > mat_z# and z# < (mat_size_z + mat_z#)
h#=get ground height(1,x#-mat_x#,z#-mat_z#) : v#=y#-h#-mat_y# : if v# >= 0 then t=1 : exit
endif
next h
if t=1
tx=int((x#-mat_x#)/(mat_size_x/mat_tiles_x))
tz=int((z#-mat_z#)/(mat_size_z/mat_tiles_z))
endif
endif
endif
return
If your mansion house needs haunting, just call Rentaghost!