Posted: 25th Aug 2006 15:52
I am trying to make a space flight simulator that has a little indicator in a corner of the screen that tells you what directon you need to turn to face your target. I know I need to make an invisible object that is in the same position as your ship but points to your target. Then I need to compare the orientation of the pointer with the orientation of the ship (the camera). But, when I use the "camera angle y()" functon, some weird glitch happens.
[img]C:/Documents and Settings/Michael/Desktop/Temporary/diagram.gif[/img]
`create world
randomize timer()
autocam off
center text 320,240,"Loading, please wait...."
position mouse 320,240
hide mouse
sync on
sync
dim missilemove(10)
dim bullet#(100)
position camera 0,0,0
speed#=0
load bitmap "grass-3.bmp",1
get image 1,0,0,256,256
delete bitmap 1
load bitmap "bmp/target.bmp",2
get image 2,0,0,64,64
delete bitmap 2
load bitmap "bmp/meter.bmp",3
get image 3,0,0,16,128
delete bitmap 3
load bitmap "bmp/meterpointer.bmp",4
get image 4,0,0,16,16
delete bitmap 4
load bitmap "bmp/example2.bmp",5
get image 5,0,0,276,260
delete bitmap 5
make object sphere 2,50
make object cube 100,5
make object sphere 1,20
position object 2,-1000,2500,-1550
position object 100,0,0,500
position light 0,1000,2500,1000
set light range 0,15000
set ambient light 50
texture object 2,1
set camera range 1,6000
make object sphere 3,11
position object 3,-500,104,-500
color object 3,rgb(255,0,0)
color object 100,rgb(0,255,0)
make light 1
make light 2
make light 3
make light 4
make light 5
make light 6
position light 1,500,115.5,500
position light 2,500,-96.5,500
position light 3,511.5,104,500
position light 4,488.5,104,500
position light 5,500,104,511.5
position light 6,500,104,488.5
for x=4 to 19
make object sphere x,0.1
next x
position object 4,2,2,rnd(90)-40
position object 5,-2,2,rnd(90)-40
position object 6,2,-2,rnd(90)-40
position object 7,-2,-2,rnd(90)-40
position object 8,1,2.75,rnd(90)-40
position object 9,0,3.5,rnd(90)-40
position object 10,-1,2.75,rnd(90)-40
position object 11,1,-2.75,rnd(90)-40
position object 12,0,-3.25,rnd(90)-40
position object 13,-1,-2.75,rnd(90)-40
position object 14,2.75,-1,rnd(90)-40
position object 15,3.25,0,rnd(90)-40
position object 16,2.75,1,rnd(90)-40
position object 17,-2.75,1,rnd(90)-40
position object 18,-3.25,0,rnd(90)-40
position object 19,-2.75,-1,rnd(90)-40
xtarget=-1000
ytarget=2500
ztarget=-1550
earthlife=100
obj0life=200
health=128
color backdrop rgb(0,0,0)
DO
`pitch controls
if upkey()=1
pitch#=pitch#-0.1
endif
if downkey()=1
pitch#=pitch#+0.1
endif
`turn controls
if leftkey()=1
turn#=turn#-0.1
endif
if rightkey()=1
turn#=turn#+0.1
endif
`roll controls
if keystate(51)=1
roll#=roll#-0.1
endif
if keystate(52)=1
roll#=roll#+0.1
endif
`speed controls
if keystate(12)=1
speed#=speed#-0.01
endif
if keystate(13)=1
speed#=speed#+0.01
endif
`speed limits
if speed#<0 then speed#=0
if speed#>4 then speed#=4
if pitch#<-3 then pitch#=-3
if pitch#>3 then pitch#=3
if turn#<-3 then turn#=-3
if turn#>3 then turn#=3
if roll#<-3 then roll#=-3
if roll#>3 then roll#=3
`plane object
position object 1,xplane,yplane,zplane
set object to camera orientation 1
`move
move camera speed#
pitch camera up pitch#
turn camera right turn#
roll camera right roll#
`variables
xplane#=camera position x()
yplane#=camera position y()
zplane#=camera position z()
xangleplane#=camera angle x()
yangleplane#=camera angle y()
zangleplane#=camera angle z()
`fricton
if downkey()=0 and upkey()=0 and pitch#>0 then pitch#=pitch#-0.1
if downkey()=0 and upkey()=0 and pitch#<0 then pitch#=pitch#+0.1
if leftkey()=0 and rightkey()=0 and turn#>0 then turn#=turn#-0.1
if leftkey()=0 and rightkey()=0 and turn#<0 then turn#=turn#+0.1
if keystate(51)=0 and keystate(52)=0 and roll#>0 then roll#=roll#-0.1
if keystate(51)=0 and keystate(52)=0 and roll#<0 then roll#=roll#+0.1
if pitch#<0.1 and pitch#>-0.1 then pitch#=0
if turn#<0.1 and turn#>-0.1 then turn#=0
if roll#<0.1 and roll#>-0.1 then roll#=0
`parameters
if camera position x()>3000
position camera 3000,yplane,zplane
endif
if camera position x()<-3000
position camera -3000,yplane,zplane
endif
if camera position y()>3000
position camera xplane,3000,zplane
endif
if camera position y()<-3000
position camera xplane,-3000,zplane
endif
if camera position z()>3000
position camera xplane,yplane,3000
endif
if camera position z()<-3000
position camera xplane,yplane,-3000
endif
`dust
for dust=4 to 19
if object in screen(dust)=0
position object dust,xplane#+rnd(100)-50,yplane#+rnd(100)-50,zplane#+rnd(100)-50
endif
next dust
`destroy object if dead
if earthlife=0
delete object 2
earthlife=-1
endif
if obj0life=0
delete object 100
obj0life=-1
endif
`destroy you if dead
if health=0 then end
`timer
timer=timer+1
`print
set cursor 0,0
print "Scancode: ",scancode()
print "Speed: ",(speed#*25)
paste image 3,0,346
paste image 4,16,(480-(speed#*32)-14)
print "x angle: ",xangleplane#
print "y angle: ",yangleplane#
print "z angle: ",zangleplane#
`syncronize screen
sync
LOOP