I would start simple with the sparky's code for collision then add the gun swaying as camera movement afterward. Far simpler that way around.
I'll whip up a really basic demo of using sparky's (I assume you'll want jumping)... give me a bit of time...
If I get time I'll add in how I'd do the camera bobbing. Oh wait I did that on my game 'The Waystation'. I'll take a look...
EDIT: Here's the simple demo (no bobbing yet):
EDIT 2: Added bobbing
Rem Project: SparkysDemo
Rem Created: Friday, April 08, 2011
Rem ***** Main Source File *****
sync on : sync rate 40 : autocam off
set camera range 0.1,200
`make player
#constant plyr 1
make object sphere plyr,0.5
position object plyr,0,0.5,0
`make a gun
#constant gun 100
make object box gun,.1,.1,.5
position object gun,.2,-.1,.2
glue object to limb gun,plyr,0
`make a ground plane
make object box 2,100,2,100
position object 2,0,-1,0
color object 2,rgb(0,255,0)
sc_setupobject 2,1,2
`make some things to bump into
for x=3 to 30
make object box x,(1+rnd(100))*.1,(1+rnd(100))*.1,(1+rnd(100))*.1
yrotate object x,rnd(359)
move object x,10+rnd(50)
rotate object x,0,0,0
color object x,rgb(rnd(255),rnd(255),rnd(255))
sc_setupobject x,1,2
next
do
`get input
forward# = (keystate(17)-keystate(31))*0.15
strafe# = (keystate(32)-keystate(30))*0.15
turn# = mousemovex()*.3
pspace = space
space = spacekey()
`move player
`save old position
oldx# = object position x(plyr)
oldy# = object position y(plyr)
oldz# = object position z(plyr)
`do movement
move object plyr, forward#
move object right plyr, strafe#
turn object right plyr, turn#
`save new position
newx# = object position x(plyr)
newy# = object position y(plyr)
newz# = object position z(plyr)
`collision code
`first deal with horizontal movement
coll = sc_sphereslidegroup(1,oldx#,oldy#,oldz#,newx#,newy#,newz#,0.5,0)
if coll>0
newx#=sc_getcollisionslidex()
newy#=sc_getcollisionslidey()
newz#=sc_getcollisionslidez()
endif
position object plyr,newx#,newy#,newz#
`now vertical
`reduce velocity in y (vy#)
vy# = vy#-0.06
if vy# < -1 then vy#=-1
`save old position
oldx# = newx#
oldy# = newy#
oldz# = newz#
`move player using vy#
move object up plyr, vy#
`save new position
newy# = object position y(plyr)
`check for a collision
ground=0
vcoll = sc_spherecastgroup(1,oldx#,oldy#,oldz#,newx#,newy#,newz#,0.5,0)
if vcoll>0
ground=1
`save new y if collision found
newy# = sc_getstaticcollisiony()
`reset vy#
vy#=0
`do a jump when on the ground
if space>0 then vy#=1
endif
`set final position
position object plyr,newx#,newy#,newz#
`camera
`edit bobbing position
t#=timer()
bobx#=sin(t#)*.5
boby#=sin(t#+30)*.5
position camera newx#,newy#,newz#
if (forward#<>0 or strafe#<>0) and ground>0
move camera right bobx#
move camera up boby#
idealx#=camera position x()
idealy#=camera position y()
idealz#=camera position z()
move camera right -bobx#
move camera up -boby#
else
idealx#=camera position x()
idealy#=camera position y()
idealz#=camera position z()
endif
position camera newx#+(idealx#-newx#)*.05,newy#+(idealy#-newy#)*.05,newz#+(idealz#-newz#)*.05
set camera to object orientation plyr
sync
loop