This code moves and rotates the camera dynamically. Press the LMB to move forward and the RMB to move backward. It moves the cube/camera whichever way you are facing. If you want to adapt it to only move on the x and z axis, it could be easily modified.
cls
sync on
sync rate 30
hide mouse
`just set up a scene
make object cube 1,100
position object 1,500.0,50.0,500.0
make matrix 1,10000,10000,30,30
`this is just an important variable
o# = 0
do
`record object position
x# = object position x(1)
z# = object position z(1)
y# = get ground height(1,x#,z#)
position object 1,x#,y#,z#
`Lets make sure the camera has a restricted y position (200 above the object)
position camera x#, y# + 100, z#
`camera rotate positions
crx#=camera angle x()
cry#=camera angle y()
crz#=camera angle z()
`mouse position
mx# = mousemovex()
my# = mousemovey()
crx# = wrapvalue(crx# + my#) : xrotate camera crx#
crz# = wrapvalue(crz# + my#) : zrotate camera crz#
mc = mouseclick()
if mc = 1
x# = newxvalue(x#,cry#,5.0)
z# = newzvalue(z#,cry#,5.0)
y# = get ground height(1,x#,z#)
position object 1,x#,y#,z#
endif
if mc = 2
x# = newxvalue(x#,cry#,-5.0)
z# = newzvalue(z#,cry#,-5.0)
y# = get ground height(1,x#,z#)
position object 1,x#,y#,z#
endif
`follow the object
if keystate(17)=0 and keystate(31)= 0 then inc o#,1
if o# > 10 then o# = 10
if o# < 10 then SET CAMERA TO OBJECT ORIENTATION 1
if keystate(17)=1 or keystate(31)=1 then o# = 0
if keystate(30)=0 then inc o#,1
if o# > 10 then o# = 10
if o# < 10 then SET CAMERA TO OBJECT ORIENTATION 1
if keystate(30)=1 then o# = 0
if keystate(32)=0 then inc o#,1
if o# > 10 then o# = 10
if o# < 10 then SET CAMERA TO OBJECT ORIENTATION 1
if keystate(32)=1 then o# = 0
`360 camera movement
rotate camera crx#+((my#+0.0)/2.0),cry#+((mx#+0.0)/2.0),0
sync
loop
I'm not really a programmer.....I only play one on TGC.