[edit] This may not help at all stick to hyrichter's post mainly. I don't know how on this earth I ended up in the DBC forum. Guess I'm sleepier than I thought.
I don't have my DBP set up for .3ds so I converted a .3ds model to .dbo and that code
a=1
load object "H-AK47-Static.dbo",1
scale object 1,1000,1000,1000
fix object pivot 1
set object 1,1,1,1
lock object on 1
load 3dsound "test.wav",1
sync on
sync rate 40
do
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
camanglex#=camera angle x()
camangley#=camera angle y()
camanglez#=camera angle z()
gun_placement(1)
mouse_look()
if mouseclick()=1
gosub shoot
endif
sync
loop
function gun_placement(obj)
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
position object obj,camx#+2,camy#-2,camz#+3
position listener object position x(1),object position y(1),object position z(1)
rotate listener 0,camera angle y()-180,0
endfunction
function mouse_look()
oldcamangley# = camangley#
oldcamanglex# = camanglex#
camangley# = wrapvalue(camangley#+MousemoveX()*.2)
camanglex# = wrapvalue(camanglex#+MousemoveY()*.2)
yrotate camera curveangle(camangley#,oldcamangley#,24)
xrotate camera curveangle(camanglex#,oldcamanglex#,24)
endfunction
shoot:
move object 1,-1
play sound 1
sleep 20
move object 1,1
return
Works for me. At least the gun is locked to the screen and showing. The firing code doesn't work though because you are moving the gun back to fire and then returning it without a sync command between them so you never see the gun move. Also the mouselook code is a bit messed up here.
Here are some changes. They are not the best way to do things but I kept them close to the way you were doing them to help make it clearer what I was doing.
global camx#
global camy#
global camz#
global camanglex#
global camangley#
global camanglez#
`no idea what this a=1 is for ?
a=1
`make matrix just so you can see gun locked on and mouse look.
make matrix 1, 1000, 1000, 20, 20
position matrix 1, -500, -10, -500
`load gun and set properties
load object "H-AK47-Static.dbo",1
scale object 1,1000,1000,1000
fix object pivot 1
set object 1,1,1,1
lock object on 1
`load sound
load 3dsound "test.wav",1
`sync and mouse stuff
sync on
sync rate 40
hide mouse
do
gun_placement(1)
mouse_look()
if mouseclick()=1
if mouseclicked = 0
mouseclicked = 1
gosub shoot
endif
else
mouseclicked = 0
endif
sync
loop
function gun_placement(obj)
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
position object obj,camx#+2,camy#-2,camz#+3
position listener object position x(1),object position y(1),object position z(1)
rotate listener 0,camera angle y()-180,0
endfunction
function mouse_look()
`rotate camera by mousemove commands
rotate camera camanglex#+(mousemovey()*.5),camangley#+(mousemovex()*.5),0
camanglex#=camera angle x()
camangley#=camera angle y()
camanglez#=camera angle z()
`keep player from looking higher then straight up or lower than straight down.
if wrapvalue(camanglex#)>90 and wrapvalue(camanglex#)<180 then xrotate camera 90
if wrapvalue(camanglex#)>180 and wrapvalue(camanglex#)<270 then xrotate camera 270
endfunction
shoot:
`made movement smaller
move object 1,-.25
`added sync to show gun moved you will want to redo this a better way
`like timer based movement instead of adding an extra sync Just move
`the gun back and return to your program and let a timer move it
`back forward for you after the main loop syncs.
sync
play sound 1
sleep 20
move object 1,.25
return
Hope this helps. To sleep now. Good luck.