hide mouse : backdrop on
color backdrop rgb(150,150,150)
set window on
set display mode 800,600,32
set window size 800,600
global objposx#,objposy#,objposz#,hitflag
make object box 1,10,10,10 : color object 1, rgb(255,0,0)
position object 1,0,0,0
make object box 2,10,10,10 : color object 2, rgb(255,0,255)
position object 2,100,0,0
make object box 3,10,10,200 : color object 3, rgb(255,255,255)
position object 3,200,0,0
make object box 4,10,10,200 : color object 4, rgb(255,255,255)
position object 4,-100,0,0
make object sphere 5,4 : color object 5, rgb(255,255,255)
position object 5,50,0,0
Do
ObjPosX#=Object Position X(1)
ObjPosY#=Object Position Y(1)
ObjPosZ#=Object Position Z(1)
ballcol()
IF UPKEY()
Move Object 1,.2
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),50,30,50,1
EndIF
If DOWNKEY()
Move Object 1,-.2
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),50,30,50,1
EndIF
If LEFTKEY()
Turn Object Left 1,.2
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),50,30,50,1
EndIF
If RIGHTKEY()
Turn Object RIGHT 1,.2
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),50,30,50,1
EndIF
for n=2 to 5
if object hit(1,n)=1 then position object 1,objposx#-.5,0,objposZ#
next n
set cursor 0,0
print hitflag
Sync
Loop
wait key
function ballcol
If object collision(1,5)=1 then hitflag=1
if hitflag=1 then position object 5,objposx#,10,objposz#
point object 5, ObjPosX#, PObjPosY#, ObjPosZ#
rem move object 5,.2
rem Endif
EndFunction
1) variables inside functions are not seen unless made global
2) you must keep track of your happened collision with a flag