Try this:
set display mode desktop width(), desktop height(), 32
sync on : sync rate 60 : sync
autocam off
` set camera's initial position and orientation
position camera 0, 50, -500
point camera 0, 25, 0
`make an object for the camera to follow
make object cube 1, 10
position object 1, 0, 25, 500
` make lots of other fixed objects, coloured green, so we can see what's happening
for obj = 2 to 180
make object cube obj, 5
color object obj, rgb(0,255,0)
position object obj, 500*sin(2*obj), 10, 500*cos(2*obj)
next obj
angle# = 0.0
fPressed = 0
repeat
text 20, 20, "Press f to make camera follow white cube"
if inkey$() = "f" then fPressed = 1
inc angle#
position object 1, 500*sin(angle#), 25, 500*cos(angle#)
px# = object position x(1)
py# = object position y(1)
pz# = object position z(1)
if fPressed then set camera to follow px#, py#, pz#, 10.0, 200.0, 25.0, 10.0, 0
sync
until spacekey()
end
You need to use
set camera to follow each loop. Use an auxiliary variable to record whether a key has already been pressed.