replace dz#=
ey#-object position z(2) by
dz#=ez#-object position z(2) and it works nice
`distance related
dx#=ex#-object position x(2)
dy#=ey#-object position y(2)
dz#=ez#-object position z(2)
Tips : make a function "distance(obj1,obj2)"
function (obj1,obj2)
`variables for object 1's position
ex#=object position x(obj1)
ey#=object position y(obj1)
ez#=object position z(obj1)
`distance related
dx#=ex#-object position x(obj2)
dy#=ey#-object position y(obj2)
dz#=ey#-object position z(obj2)
`doesnt seem to work-going toward camera
distance = sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
endfunction distance
put it a t the end of you main source or better in a separate #include
then you source will be more lighty and clear :
`*** testing (trying to figure things out) ***
rem miscellaneous start up code
`make objects
make object box 1,10,10,10
make object box 2,10,10,10
position object 2,-11,0,-18
`turn off default cam
autocam off
make camera 1
yrotate camera 1,200
set current camera 1
position camera 1,10,12,30
`*** main loop ***
do
distance=distance(1,2)
`check for distance between object 1 & object 2
if distance<20 and controlkey()
print "theres object 2"
endif
print distance
rem move player
if upkey()
move object 1,0.1
endif
if downkey()
move object 1,-0.1
endif
if leftkey()
turn object left 1,1
endif
if rightkey()
turn object right 1,1
endif
loop
`*** end of main loop ***
REM the distance function here
function (obj1,obj2)
`variables for object 1's position
ex#=object position x(obj1)
ey#=object position y(obj1)
ez#=object position z(obj1)
`distance related
dx#=ex#-object position x(obj2)
dy#=ey#-object position y(obj2)
dz#=ey#-object position z(obj2)
`doesnt seem to work-going toward camera
distance = sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
endfunction distance