Actually your code works if you use it correctly. What
values are you using for camon, etc?
Here's what I used to test your code (I used the default camera 0 - but you should be able to use any camera with your code):
sync on : sync rate 60 : sync
autocam off
position camera 0, 100, 0
point camera 0, 0, 0
make object sphere 1, 30
position object 1, 100, 0, 0
make object cube 2, 25
position object 2, -100, 0, 0
null = make vector3(1)
repeat
if inkey$() = "c"
` find the dist between camera and object 1
text 20, 20, "cam/obj dist = "+str$(GetDist(0, 0, 1, 2), 2)
else
` find the dist between object 1 and object 2
text 20, 20, "cam/obj dist = "+str$(GetDist(1, 0, 1, 2), 2)
endif
sync
until spacekey()
end
function GetDist(camon,cam,obj1,obj2)
select camon
case 0
if obj2<>0
x1#=Camera Position X(cam)
y1#=Camera Position Y(cam)
z1#=Camera Position Z(cam)
x2#=Object Position X(obj1)
y2#=Object Position Y(obj1)
z2#=Object Position Z(obj1)
endif
endcase
case 1
if obj1<>0 and obj2<>0
x1#=Object Position X(obj2)
y1#=Object Position Y(obj2)
z1#=Object Position Z(obj2)
x2#=Object Position X(obj1)
y2#=Object Position Y(obj1)
z2#=Object Position Z(obj1)
endif
endcase
endselect
dist# = Dist(x1#,x2#,y1#,y2#,z1#,z2#)
endfunction dist#
Function Dist(x1#,x2#,y1#,y2#,z1#,z2#)
Set Vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
dist#=Length Vector3(1)
EndFunction dist#