well..try this code and study it... i hope it can help
or use the part that you need...
the bullet is the small sphere visible on the cube gun..
it is offsetted with sin/cos in order to stay in position when turning the cube..
use arrows to move and turn..
cheers
Rem * Title : Camtrials
Rem * Author : Scorpyo
Rem * Date : July2001
rem by Scorpyo
rem bullet realtime offset
rem sky= object 99
rem ********** MAIN 1 ****************
hide mouse
sync on
grid=30
landsize=10000
gosub Setupland1
gosub Character
gosub Vars1
set global collision off
active=1
sync rate 0
set camera range 1,9000
rem position object 5,4950,90,4950
gosub Resetcam
rem *****MAIN LOOP******
do
rem -------------------------------------------
if inkey$()="s" then camrot=wrapvalue(camrot+2)
rem -------------------------------------------
if inkey$()="a" then a#=0
basetime = timer()
if playertime < basetime then gosub Playercontrol
if inkey$()="w" then fog distance 1000
if inkey$()="q" then fog distance 10000
gosub camera_controls
rem Calculate position data
oldx#=x#
oldz#=z#
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
gosub update_camera
rem Update active model
h#=get ground height(1,x#,z#)
position object 1,x#,h#+5,z#
yrotate object 1,a#
gosub bulletpos
rem Sky follows active character
position object 99,x#,0,z#
rem Update screen
sync
rem End loop
loop
rem ** SUBROUTINES ***************************
rem ****** CREATE LAND1 ******
Setupland1:
make matrix 1,landsize,landsize,grid,grid
update matrix 1
return
rem ******** VARIABLES ******
rem ****VARS1****
Vars1:
rem
fullrot=360
active=1
rem **Start position**
x#=landsize/2
z#=landsize/2
camdist=-300
camhgt=200
camrot=0
camlen=100
rem forced timing
basetime = timer()
playertime = basetime
return
rem ***** PLAYERCONTROL *****
Playercontrol:
set cursor 0,0
print "Fps=",screen fps()
print "landsize=",landsize
print "grid=",grid
print "x=",x#
print "z=",z#
print "a#=",a#
print "bullx#=",bullx#
print "bullz#=",bullz#
rem ****Character****
if active=1
if upkey()=1 and s#<12 then s#=s#+2
if downkey()=1 and s#>-12 then s#=s#-2
if leftkey()=1 then a#=wrapvalue(a#-4)
if rightkey()=1 then a#=wrapvalue(a#+4)
endif
rem stop if "-"
if inkey$()="-" then s#=0.0
rem calls timing
playertime = basetime + 30
return
rem ***CONTROL EXTENSIONS ******
rem empty
rem ****ACTIVE CHARACTER****
Character:
rem tank
make object cube 1,200
scale object 1,100,60,200
rem cannon
make object cube 2,40
scale object 2,100,100,300
make mesh from object 1,2
add limb 1,1,1
offset limb 1,1,50,120,50
rem bullet
make object sphere 5,30
return
camera_controls:
if inkey$()="<" then camrot2=wrapvalue(camrot2)+2
if inkey$()="z" then camdist=camdist+2
if inkey$()="x" then camdist=camdist-2
if inkey$()="b" then camrot=camrot+2
if inkey$()="n" then camrot=camrot-2
if inkey$()="c" then camhgt=camhgt+2
if inkey$()="v" then camhgt=camhgt-2
if inkey$()="m" then camlen=camlen+2
if inkey$()="," then camrot = 180
if inkey$()="." then gosub Resetcam
return
update_camera:
rem Position camera to the back of the character
cx#=newxvalue(x#,wrapvalue(a#+camrot),camdist)
cz#=newzvalue(z#,wrapvalue(a#+camrot),camdist)
cy#=get ground height(1,cx#,cz#)+playhgt
position camera cx#,cy#+camhgt,cz#
rem Point camera at object
point camera x#,y#+camlen,z#
return
rem camera reset
Resetcam:
camdist=-400
camhgt=200
camrot=0
camlen=100
return
bulletpos:
tankangle#=object angle y(1)
bullz#=z#+sin(tankangle#) * -50
bullx#=x#+cos(tankangle#) * 50
position object 5,bullx#,90,bullz#
return