Hey, sorry about the time shift from here to there. It was midnight and I needed some sleep.
I did some reworking of the program structure to make things a little easier. I've included the forward and backward velocity caps along with the home key acceleration. I also wrote a rounding function to display a certain amount of decimal places. I don't know if there's an easier way built into DBPro, but a quick search turned up nothing.
sync rate 60
sync on
autocam off
mapsize=500
sky=5001
load image "sky.bmp",sky
make object sphere sky,(-mapsize*2)
texture object sky,sky
position object sky,mapsize/2,0,mapsize/2
make object sphere 1,5
position object 1,0,0,35
position camera 35,0,35
RollVelocity#=0
RollAcceleration#=0.06
RollDeceleration#=0.03
PitchVelocity#=0
PitchAcceleration#=0.06
PitchDeceleration#=0.03
ThrustVelocity#=0
ThrustAcceleration#=0.06
ThrustDeceleration#=0
dim VelocityCap#(3)
VelocityCap#(1)=2 `Forward
VelocityCap#(3)=0.6 `Backward
do
`Increase or decrease velocities
if rightkey() then inc RollVelocity#,RollAcceleration#
if leftkey() then dec RollVelocity#,RollAcceleration#
if upkey() then dec PitchVelocity#,PitchAcceleration#
if downkey() then inc PitchVelocity#,PitchAcceleration#
if keystate(17) then inc ThrustVelocity#,ThrustAcceleration# : ThrustDeceleration#=0
if keystate(31) then dec ThrustVelocity#,ThrustAcceleration# : ThrustDeceleration#=0
RollSign=Sign(RollVelocity#)
PitchSign=Sign(PitchVelocity#)
ThrustSign=Sign(ThrustVelocity#)
`Cap velocities at +/- 5
if abs(RollVelocity#)>5 then RollVelocity#=RollSign*5
if abs(PitchVelocity#)>5 then PitchVelocity#=PitchSign*5
if abs(ThrustVelocity#)>VelocityCap#(2-ThrustSign) then ThrustVelocity#=ThrustSign*VelocityCap#(2-ThrustSign)
`Print variables
set cursor 0,0
print Round(RollVelocity#,2)
print Round(PitchVelocity#,2)
print Round(ThrustVelocity#,2)
`Actually turn the camera
roll camera right RollVelocity#
pitch camera up PitchVelocity#
move camera ThrustVelocity#
`Bring the velocities closer to zero.
if abs(RollVelocity#)>0 then dec RollVelocity#,RollSign*RollDeceleration#
if RollSign<>Sign(RollVelocity#) then RollVelocity#=0
if abs(PitchVelocity#)>0 then dec PitchVelocity#,PitchSign*PitchDeceleration#
if PitchSign<>Sign(PitchVelocity#) then PitchVelocity#=0
if keystate(207) then ThrustDeceleration#=0.07
if keystate(199) then ThrustDeceleration#=-0.07
if abs(ThrustVelocity#)>=0 then dec ThrustVelocity#,ThrustSign*ThrustDeceleration#
if ThrustSign<>Sign(ThrustVelocity#)
ThrustVelocity#=0
ThrustDeceleration#=0
endif
sync
loop
`Returns the sign of a#
function Sign(a#)
sign=1
if a#<0 then sign=-1
endfunction sign
function Round(a#,Places)
a$=str$(a#)
DecimalPoint=InString(a$,".",1)
if not DecimalPoint then exitfunction a#
if InString(a$,"e",1) then exitfunction 0.0
LastChar$=right$(left$(a$,DecimalPoint+Places+1),1)
a#=val(left$(a$,DecimalPoint+Places))
if int(val(LastChar$))>=5 then inc a#,1.0/10^Places
endfunction a#
function InString(a$,b$,Start)
for a=Start to len(a$)
if right$(left$(a$,a),1)=b$ then exitfunction a
next a
a=0
endfunction a
I don't know if the home key works exactly as you envisioned it, but currently, if pressed, the camera will accelerate until it has reached the velocity cap for the direction in which it was traveling. Pressing the home key while stationary causes an automatic acceleration in the forward direction. Also, any forward or backward movement from the user cancels any acceleration. I'm sure changes could be easily made if this isn't what you had in mind.