I'm having trouble with angles.
I have a jet fighter, and the physics seem to work fine, but when you turn around, up becomes down and down becomes up!
Please don't mind the indenting, that's just how I do it, and it's not as big of an indent in the DB editor.
rem set settings
set display mode 1024,768,32
sync rate 0
sync on
set camera range 1,10000
set mipmap mode 2
autocam off
hide mouse
rem load images
gosub LoadImages
rem load models
gosub LoadModels
rem initialize game variables
rem vehicles
CURRENTVEHICLE=10000
rem jet fighters
dim JETTHROTTLE#(100)
dim JETSPEED#(100)
dim JETTURNTILT#(100)
dim JETPITCH#(100)
rem beginning of main game loop
do
rem print information
set cursor 0,0
print "FPS: ";screen fps()
print "Scancode: ";scancode()
print "tilt: ";JETTURNTILT#(curjet)
print "pirch: ";JETPITCH#(curjet)
rem control vehicles
rem jet fighters
if CURRENTVEHICLE>=10000 and CURRENTVEHICLE<10100
gosub ControlJetFighters
endif
rem sycronize
sync
rem end of main game loop
loop
rem control jet fighters
ControlJetFighters:
rem current jet fighter
curjet=CURRENTVEHICLE-9999
unitcontrol=CURRENTVEHICLE+10000
cameracontrol=CURRENTVEHICLE+20000
rem movement
rem input control
rem increase throttle
if keystate(30)=1
if JETTHROTTLE#(curjet)<20
JETTHROTTLE#(curjet)=JETTHROTTLE#(curjet)+.01
endif
endif
rem decrease throttle
if keystate(44)=1
if JETTHROTTLE#(curjet)>0
JETTHROTTLE#(curjet)=JETTHROTTLE#(curjet)-.01
endif
endif
rem turn left
if leftkey()=1
if JETTURNTILT#(curjet)<50 or JETTURNTILT#(curjet)>=310
JETTURNTILT#(curjet)=wrapvalue(JETTURNTILT#(curjet)+.5)
endif
endif
rem turn right
if rightkey()=1
if JETTURNTILT#(curjet)>310 or JETTURNTILT#(curjet)<=51
JETTURNTILT#(curjet)=wrapvalue(JETTURNTILT#(curjet)-.5)
endif
endif
rem pull up
if downkey()=1
rem left
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)<180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)-JETTURNTILT#(curjet)/50)
endif
rem right
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)>180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)+(360-JETTURNTILT#(curjet))/50)
endif
rem pull up
rem if JETPITCH#(curjet)>315 or JETPITCH#(curjet)<45
JETPITCH#(curjet)=wrapvalue(JETPITCH#(curjet)-.5)
rem endif
endif
rem pull down
if upkey()=1
rem left
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)<180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)+JETTURNTILT#(curjet)/50)
endif
rem right
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)>180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)-(360-JETTURNTILT#(curjet))/50)
endif
rem pull down
rem if JETPITCH#(curjet)<45 or JETPITCH#(curjet)>315
JETPITCH#(curjet)=wrapvalue(JETPITCH#(curjet)+.5)
rem endif
endif
rem output control
rem match speed to throttle
if JETSPEED#(curjet)<JETTHROTTLE#(curjet)
JETSPEED#(curjet)=JETSPEED#(curjet)+.01
endif
if JETSPEED#(curjet)>JETTHROTTLE#(curjet)
JETSPEED#(curjet)=JETSPEED#(curjet)-.01
endif
rem make plane have a slight turning effect
rem left
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)<180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)-JETTURNTILT#(curjet)/200)
endif
rem right
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)>180
yrotate object CURRENTVEHICLE,wrapvalue(object angle y(CURRENTVEHICLE)+(360-JETTURNTILT#(curjet))/200)
endif
rem level out plane if not controlling
rem not turning
if leftkey()=0 and rightkey()=0
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)>180
JETTURNTILT#(curjet)=wrapvalue(JETTURNTILT#(curjet)+.5)
endif
if JETTURNTILT#(curjet)>0 and JETTURNTILT#(curjet)<180
JETTURNTILT#(curjet)=wrapvalue(JETTURNTILT#(curjet)-.5)
endif
endif
rem not pitching
if upkey()=0 and downkey()=0
if JETPITCH#(curjet)>0 and JETPITCH#(curjet)>180
JETPITCH#(curjet)=wrapvalue(JETPITCH#(curjet)+.5)
endif
if JETPITCH#(curjet)>0 and JETPITCH#(curjet)<180
JETPITCH#(curjet)=wrapvalue(JETPITCH#(curjet)-.5)
endif
endif
rem rotate plane and unit control
rem unit control
xrotate object unitcontrol,JETPITCH#(curjet)
yrotate object unitcontrol,object angle y(CURRENTVEHICLE)
zrotate object unitcontrol,JETTURNTILT#(curjet)
rem camera control
rem xrotate object cameracontrol,JETPITCH#(curjet)
yrotate object cameracontrol,object angle y(CURRENTVEHICLE)
rem tilt jet
xrotate object CURRENTVEHICLE,JETPITCH#(curjet)
zrotate object CURRENTVEHICLE,JETTURNTILT#(curjet)
rem move unit control and position plane on unit control
move object unitcontrol,JETSPEED#(curjet)
position object CURRENTVEHICLE,object position x(unitcontrol),object position y(unitcontrol),object position z(unitcontrol)
rem camera control
position object cameracontrol,object position x(unitcontrol),object position y(unitcontrol),object position z(unitcontrol)
move object cameracontrol,-10
position camera object position x(cameracontrol),object position y(cameracontrol)+5,object position z(cameracontrol)
point camera object position x(unitcontrol),object position y(unitcontrol),object position z(unitcontrol)
return
rem load images
LoadImages:
rem vehicles
rem planes
rem jet fighter
load bitmap "MediaTexturesVehiclesPlanesJetFigh2.bmp",1
get image 100,0,0,512,512
delete bitmap 1
return
rem load models
LoadModels:
rem vehicles
rem planes
rem jet fighter
rem model
load object "MediaModelsVehiclesPlanesH-Jet Fighter 2-Move.x",10000
texture object 10000,100
yrotate object 10000,180
fix object pivot 10000
rem unit control
make object cube 20000,50
set object collision off 20000
hide object 20000
position object 20000,500,5,500
rem camera control
make object cube 30000,50
set object collision off 30000
hide object 30000
make matrix 1,1000,1000,70,70
return
Since media files are required, I've attached an exe.
Controls:
left arrow=turn left
right arrow=turn right
up arrow=pitch down
down arrow=pitch up
a=throttle up
z=throttle down
Thanks
Uncle Sam
--------------
Uncle Sam