Not trying to spoil the learning experience for you - so don't look at this code if you want to figure it out by yourself .... but if you get stuck on using the pick object commands to get distances of 3d objects from 2d coordinates, this will help you see how to do it:
Rem Project: starflied5
Rem Created: 20/12/2004 16:45:34
Rem ***** Main Source File *****
sync on
autocam off
color backdrop 0
ink rgb(80,80,255),0
hide mouse
global stars=200,ship=0,mb#=10.0
Dim star_ang#(stars)
Dim star_rad#(stars)
Dim star_spd#(stars)
dim ship_ang#(ship)
dim ship_rad#(ship)
dim ship_spd#(ship)
dim ship_zis#(ship)
sw=screen width()
sh=screen height()
rem make stars
for st=0 to stars
star_ang#(st)=rnd(36000)/100.00
star_rad#(st)=rnd(sw/2)
star_spd#(st)=0.5+abs(sin(rnd(360)))
next st
`make ships
numberofships=50
dim shipspeed#(numberofships)
for ship=1 to numberofships
make object cube ship,1
shipspeed#(ship)=rnd(10)/10+1
position object ship,rnd(20)-10,rnd(20)-10,rnd(500)
next ship
do
`move ships
for ship=1 to numberofships
move object ship,-shipspeed#(ship)
if object position z(ship)<0 then position object ship,rnd(20)-10,rnd(20)-10,500
next ship
rem show stars
for st=0 to stars
star_rad#(st)=star_rad#(st)-star_spd#(st)
if star_rad#(st)<0 then star_rad#(st)=star_rad#(st)+sw/2
px=sw/2+(sin(star_ang#(st))*star_rad#(st))
py=sh/2+(cos(star_ang#(st))*star_rad#(st))
pc=(star_rad#(st))+55
if pc>255 then pc=255
dot px,py,rgb(pc,pc,pc)
next st
`cross hairs
circle mousex(),mousey(),10
circle mousex(),mousey(),15
line mousex()-10,mousey(),mousex()+10,mousey()
line mousex(),mousey()-10,mousex(),mousey()+10
`fire gun
if mouseclick()=1
`laser lines
if laser=0
line 0,sh/1.5,mousex(),mousey()
line sw,sh/1.5,mousex(),mousey()
endif
`get object number of 3d object at 2d mouse coordinates
object=pick object(mousex(),mousey(),1,numberofships)
if object>0
`get distance from 3d object to mouse coordinates
distance=get pick distance()
if distance<100 then hide object object
endif
endif
inc laser
if laser>5 then laser=0
rem update
sync
loop
control crosshairs with mouse, fire laser with left mouse button.