I have the torpedo firing now and have collision working with a shuttle craft fying around for target practice. So things are looking better.
A few problems remain.. when the torpedo is restarted, the camera jolts backward for some reason. (I started over again and this time I left camera alone, so I don't understand this.)
Also, when ship is in motion, the torpedo just sort of falls out and sits there instead of shooting forward.
I'm attaching the code so far. Would appreciate any tips on making it work.
REM Some code from DarkBasic Professional Tutoral
init:
CLS
sync on
sync rate 0
sync
backdrop on
rem loading scout ship
load image "F01_512.jpg",1
load object "SpaceFighter02.3ds",1
set object specular 1,0
set object 1,1,1,1,0,0,0,0
set object texture 1,1,0
scale object 1,12,8,16
xrotate object 1,180
yrotate object 1,0
fix object pivot 1
rem Create object for bullet
TorpObj=3 : make object sphere TorpObj,3
color object 3,rgb(250,0,0)
TorpSnd=1 : load sound "Cannon.wav",TorpSnd
ImpactSnd=2 : load sound "LGexplosion1.wav",ImpactSnd
DistantSnd=4 : load sound "LGexplosion4.wav",DistantSnd
bullet=0
REM ENEMY SHIP INFO
seedvalue=rnd(10000)
randomize seedvalue
load image "S02_512.jpg",2
load object "Shuttle02.3ds",2
set object specular 2,0
set object 2,1,1,1,0,0,0,0
set object texture 2,2,0
scale object 2,20,35,22
hide mouse
REM TURNS MODEL AROUND.. IT WAS BACKWARDS
xrotate object 2,180
REM TURNS MODEL RIGHTSIDE UP
zrotate object 2,180
fix object pivot 2
position object 2,rnd(500),rnd(10),rnd(100)
set bsp object collision 2,20,35,22
REM MAKE SMALL ASTEROIDS
for t=1000 to 1111
make object sphere t,1.0+(rnd(375)*.01)
rem I can't get rainbow shading to work yet...its a cool effect on planets though
set rainbow shading on t,0
color object t,rgb(rnd(250),rnd(250),rnd(250))
position object t,rnd(1000),rnd(100),rnd(1000)
next t
DO
sync
rem Show Framerate
text 20,screen height()-40,desc$
fps$="MEGA EMPIRES III Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$
seedvalue=rnd(5000)
randomize seedvalue
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),40,20,50,0
move object 1,upkey()+4
move object 1,(-downkey())-4
yrotate object 1,object angle y(1)+rightkey()
yrotate object 1,object angle y(1)-leftkey()
rem Move enemy on a slow curve for appearance of intelligence
if object angle z(2)=0
yrotate object 2,wrapvalue(object angle y(2)+.2)
endif
if object angle z(2)=1
yrotate object 2,wrapvalue(object angle y(2)-.2)
endif
if object angle z(2)=2
move object 2,1
else
move object 2,1
endif
Rem TORPEDO FIRE CONTROL
if mouseclick()=1 and bullet=0
bullet=300
play sound TorpSnd
position object TorpObj,object position x(1),object position y(1),object position z(1)
rem align torpedoe to aim it with scout ship
set object to object orientation 3,1
rem i have no idea why the torp needs to be rotated
rotate object TorpObj,object angle x(1)-7,object angle y(1)+0,0
set bsp object collision 2,TorpObj,1,1
move object TorpObj,3
endif
rem If enemy and bullet in same space, enemy dies
if bullet>0
if object collision(TorpObj,2)>0
play sound DistantSnd:bullet=0
rem play object 2,26,26+50
set object speed 2,1
bulletimpact=1
endif
endif
rem if bulletimpact>0 then goto endroutine
rem Control life of bullet
if bullet>0
rem If bullet collides with BSP world
if bsp collision hit(2)=1 or bulletimpact=1
rem End bullet on wall
rem position sound ImpactSnd,object position x(TorpObj), object position y(TorpObj), object position z(TorpObj)
play sound ImpactSnd
bulletimpact=0
bullet=0:goto justbeforetheloop
else
rem Move bullet
dec bullet
move object TorpObj,0.5
endif
rem Bullet dies
if bullet=0
set bsp collision off 2
gosub makenewbullet
rem play sound DistantSnd
endif:goto justbeforetheloop
else if bullet>0 then dec bullet
endif
justbeforetheloop:
LOOP
makenewbullet:
if object exist(3):delete object 3
rem Create object for bullet
TorpObj=3 : make object sphere TorpObj,3
color object 3,rgb(250,0,0)
bullet=0
endif
return