Thanks - I was considering possible improvements but you've done it for me
Your version is better, but to get good accuracy, you need to make the object smaller (eg size 1)
A very slightly tweaked version attached.
sync on: sync rate 0
type MatrixTile
xtile
ztile
endtype
tilecountx=25
tilecountz=25
mxwidth=100
mxheight=100
totalcubes = (tilecountx+1)*(tilecountz+1)
MxPoint as MatrixTile
make matrix 1,mxwidth,mxheight,tilecountx,tilecountz
position matrix 1,0,0,0
`Create a cube for each point on the matrix
make object cube 1,1
hide object 1
space#=mxwidth/tilecountx
xrotate camera 0
do
if mouseclick()=0 or pickobj=0
`find out which matrix tile it is picking if at all
for z=0 to tilecountz
for x=0 to tilecountx
position object 1, (x*space#), get matrix height(1,x,z) ,(z*space#)
pickobj = Pick Object(MouseX(),MouseY(),1,1)
if pickobj=1
MxPoint.xtile=x
MxPoint.ztile=z
endif
if pickobj=1 then exit
next x
if pickobj=1 then exit
next z
endif
if mouseclick()=1 and pickobj=1
`Get the distance between camera and object in x and z axis
CamDist# = Distance3D(Camera Position X(),0,Camera Position Z(),Object Position X(1),0,Object Position Z(1))
`Convert the mousex / mousey position into a new Y co-ord in World3D
Pick Screen MouseX(),MouseY(),CamDist#
`Add the world Y to the camera Y given by Get Pick Vector()
newy# = Get Pick Vector Y()+Camera Position Y()
Position Object 1,Object Position X(1),newy#,Object Position Z(1)
`Adjust the matrix tile height
`There is a bug in the U5 beta where matrix height is inversed
Set Matrix Height 1,MxPoint.xtile, MxPoint.ztile,-Object Position Y(1)
`Use this line below instead when the bug is fixed
`Set Matrix Height 1,MxPoint(pickobj).xtile,MxPoint(pickobj).ztile,Object Position Y(pickobj)
Update Matrix 1
endif
Control Camera Using Arrowkeys 0,0.1,0.1
if inkey$()="a" then Position Camera Camera Position X(),Camera Position Y()+0.1,Camera Position Z()
if inkey$()="z" then Position Camera Camera Position X(),Camera Position Y()-0.1,Camera Position Z()
text 20,40,str$(pickobj)
text 20,20,str$(screen fps())
sync
loop
function Distance3D(x1#,y1#,z1#,x2#,y2#,z2#)
distx#=x2#-x1#
disty#=y2#-y1#
distz#=z2#-z1#
result#=Sqrt(abs(distx#*distx#)+abs(disty#*disty#)+abs(distz#*distz#))
endfunction result#