sines cosines and tangents
they are not that hard, this is a sine plotted over time
sync on:sync rate 20
do
for i=1 to 720
dot i,(sin(i)*200)+200
sync
next i
cls
sync
loop
that wavy line is what you need to make your gun swing from side to side, if you look at the code then you can see that all it does is plot the sine of all the degrees from one to 720 (two complete rotations), if you watch as it draws it you can see that it "moves" slower at the top and the bottom, thats what you want to make the gun move from side to side in a convincing manner, as it gets to the end of the swing then it slows down, then it swings fastest when it passes through the middle, this next snippet swings a cylinder from side to side using sine, notice that the movement looks natural
sync on:sync rate 40
make object cylinder 1,3
scale object 1,10,100,10
do
for i=1 to 360 step 10
zrotate object 1,(sin(i)*10)
sync
next i
loop
it`s rotating in the wrong plain for a gun and if you turned the object to lie flat and placed the camera behind it then you would notice that the gun swung from side to side, but not a hair up or down, this looks unatural since a gun wouldn`t swing like that when you carried it, so you add another smaller sine movement to the equation that will bob it up and down slightly, but you make this one run out of sequence with the other one by using slightly different numbers or it will just move in an ellipse and that would look unatural too
sync on:sync rate 40
make object cylinder 1,3
scale object 1,10,100,10
xrotate object 1,90
fix object pivot 1
position camera 0,2,-2
set camera range 0.01,10000
secondarybob=60
do
for i=1 to 360 step 5
secondarybob=secondarybob+8
if secondarybob>360 then secondarybob=0
yrotate object 1,(sin(i)*10)
xrotate object 1,sin(secondarybob)*2
sync
next i
loop
this make the cylinder move somewhat like a gun as you walk, but I exagerated the movement so you can see it in action easily, lower the numbers used as multipliers to make the thing not wave about so much, then all you need to do is to make those numbers relate to the speed, so that if the player is running the gun waves about a lot, and if he is walking or still the gun moves by almost nothing, hope thats some help, cheers
Mentor.
PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.