John Avon,
If you have coded the bullets to take the same angle or position of the turret while they are 'flying', that's excatly what they will do. The trick to seperate the bullet from the gun, to that the bullet continues to go the angle it started with initially, is to give the bullet values from seperate variables.
Let's say that the turret is facing an angle of 315o(slanted up) on the x axis. When you press the fire button, whatever you have coded it to be, mouselick or any keyboard key, first assign the turret's angle value to a variable which can be used by the bullet, seperate from the turret's angle variable. Then, use this variable as the bullet's constant for an angle. Try this code snippet below.
set display mode 800,600,32
sync on
sync rate 60
REM << make turret head
make object cylinder 1,4
xrotate object 1,90
fix object pivot 1
scale object 1,10,10,30
position object 1,0,7,0
REM << make bullet
make object sphere 3,1
hide object 3
REM << make turret base
make object cylinder 2,3
position object 2,0,5,0
REM << position camera at an overview
position camera 0,15,-15
xrotate camera 30
REM <<<<<<<<< main program loop >>>>>>>>>>>
repeat
REM << control turret
if upkey() = 1 then xangle# = wrapvalue(xangle# + 2)
if downkey() = 1 then xangle# = wrapvalue(xangle# - 2)
if leftkey() = 1 then yangle# = wrapvalue(yangle# - 2)
if rightkey() = 1 then yangle# = wrapvalue(yangle# + 2)
xrotate object 1,xangle#
yrotate object 1,yangle#
yrotate object 2,yangle#
REM << prepare bullet variables if spacekey is pressed
if spacekey() = 1 and bulletlife = 0
position object 3,0,7,0
REM << this line is in place of where you would fill the bullet's angle variable with the turret's current angle
set object to object orientation 3,1
show object 3
bulletlife = 100
endif
REM << if bullet is prepared, then make it 'fly'
if bulletlife > 0
dec bulletlife
REM << this line is in place of where you would use the bullet's angle to calculate it's new position;must be a seperate variable
move object 3,2
if bulletlife = 1 then hide object 3
endif
REM << print instructions to screen
center text 400,550,"press arrow keys to control turret"
center text 400,565,"press spacebar to shoot bullet from turret"
center text 400,580,"press right mouse button to end program"
sync
until mouseclick() = 2
end
In this code I did not make everything to function the way I usually do, with sin and cos and other maths. Simply, I used DarkBasic commands, but have placed REM statements in where I believe will help you to understand what's going on. Also, the turret's motion is quite awkward. However, I did not create this program to perfect it, but to show how to seperate a bullet's movement from the turret's movement.
+NanoBrain+