Spooky's code works, but gives a 'locked on a pole' feel rather than a 'chase-cam' feel.
I've made some alterations to his code to give a more natural feel.
sync on : sync rate 0 : autocam off : randomize timer()
` create stars image
for f=1 to 50 : e=rnd(255) : dot rnd(255),rnd(255),rgb(e,e,e) : next f : get image 1,0,0,256,256
`create non-zebra-like texture for spaceship
ink rgb(0,0,255),0
box 0,0,10,10
get image 2,0,0,10,10
ink rgb(255,0,0),0
box 0,0,10,10
get image 3,0,0,10,10
` create star sphere
make object sphere 9,20000,20,20 : texture object 9,1
scale object texture 9,8,8 : set object 9,1,0,0,0,0,0,0
` dodgy looking spaceship
make object box 1,20,6,50:texture object 1,2
make object cube 2,2 : glue object to limb 2,1,0 : position object 2,-5,0,-25 : texture object 2,3
make object cube 3,2 : glue object to limb 3,1,0 : position object 3,5,0,-25 :texture object 3,3
make object box 4,10,7,10 : turn object left 4,45 : glue object to limb 4,1,0 : position object 4,0,0,25 : texture object 4,3
` framework
o=99 : s=3000 : c=5
for f=0 to c-1
for g=0 to c-1
inc o : make object box o,s,2,2 : position object o,s/2,g*s/(c-1),f*s/(c-1) : color object o,rgb(255,0,0)
inc o : make object box o,2,s,2 : position object o,f*s/(c-1),s/2,g*s/(c-1) : color object o,rgb(0,255,0)
inc o : make object box o,2,2,s : position object o,f*s/(c-1),g*s/(c-1),s/2 : color object o,rgb(0,0,255)
next g
next f
set camera range 1,20000
ink rgb(140,140,255),0
set text font "arial"
set text size 16
`chasecam distance (zoom)
r#=100
`initial speed
speed#=0.5
`initial positions
position object 1,1550,1550,1550
position camera 1500,2000,0
do
`keyboard input
if keystate(203)=1 then roll object left 1,1
if keystate(205)=1 then roll object right 1,1
if keystate(200)=1 then pitch object down 1,1
if keystate(208)=1 then pitch object up 1,1
if keystate(12)=1 then speed#=speed#-0.1 : if speed# < 0 then speed#=0
if keystate(13)=1 then speed#=speed#+0.1
if keystate(23)=1 then turn object left 1,1
if keystate(25)=1 then turn object right 1,1
if inkey$()="a" and r#>10 then r#=r#-2
if inkey$()="z" then r#=r#+2
move object 1,speed#
`**********************
`*** Chase cam code ***
`**********************
dx#=object position x(1)-ox#
dy#=object position y(1)-oy#
dz#=object position z(1)-oz#
ang#=atanfull(dx#,dz#)
if ang#<0 then ang#=ang#+360
camx#=curvevalue(object position x(1)-r#*sin(ang#),camera position x(),100)
camy#=curvevalue(object position y(1),camera position y(),130)
camz#=curvevalue(object position z(1)-r#*cos(ang#),camera position z(),100)
position camera camx#,camy#,camz#
point camera object position x(1),object position y(1),object position z(1)
ox#=object position x(1)
oy#=object position y(1)
oz#=object position z(1)
`**********************
`**********************
`**********************
gosub draw_starfield
set cursor 0,0
print "FREE FLIGHT DEMO - By Spooky" : print
print "(with chase-cam by Ric, and 3d starfield by Cloggy)"
print
print "Up Arrow = Pitch Down"
print "Down Arrow = Pitch Up"
print
print "Left Arrow = Roll Left"
print "Right Arrow = Roll Right"
print
print "I = Turn Left"
print "P = Turn Right"
print
print "+ = Accelerate"
print "- = Decelerate"
print
print "A = Zoom in"
print "Z = Zoom out"
sync
loop
draw_starfield:
rem 3D Starfield Demo - Written by Jason Clogg
rem Feel free to use any of this code
rem base sprite number
base=600
rem How widely to spread the stars
spread=800
rem How many stars to display
stars=200
rem The initial distance to start the stars displaying
dist=500
`Calculate a point in front of the camera to start drawing the starfield
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
pick screen screen width()/2,screen height()/2,dist
sx#=get pick vector x()
sy#=get pick vector y()
sz#=get pick vector z()
if object exist(600)=0
make object box 600,.5,.5,.5
for i=601 to 600+stars
clone object i,600
rem stars should not be affected by light or included in collisions
set object light i,0
set object collision off i
position object i,rnd(spread*2)-spread,rnd(spread*2)-spread,camera position z()+rnd(dist)
next i
endif
for i=600 to 600+stars
`reposition stars if they are out of camera shot
if object in screen(i)=0
position object i,cx#+sx#+(rnd(spread)-(spread/2)),cy#+sy#+(rnd(spread)-(spread/2)),cz#+sz#+(rnd(spread*2)-(spread/2))
endif
`Calculate distance of star from camera and scale star accordingly
dist#=distance(cx#,cy#,cz#,i)
scale object i,.1*(dist#*2),.1*(dist#*2),2000*speed#
set object to object orientation i,1
rem The multiple of 1.2 will need to be changed depending on the frame rate.
rem This value works best with a sync rate of 60
move object i,speed#*-1.2
next i
return
function distance(x1#,y1#,z1#,obj)
x2#=object position x(obj)
y2#=object position y(obj)
z2#=object position z(obj)
dist#=sqrt((x1#-x2#)*(x1#-x2#)+(y1#-y2#)*(y1#-y2#)+(z1#-z2#)*(z1#-z2#))
endfunction dist#