For a gun firing, You'd want it to recoil fast when you fire moving backwards until it hits some sort of limit, then moving forwards again at a slower rate until it's back where it started, but having no 'hard stop' in the middle.
That describes the SIN function perfectly - just feed it an angle, ranging from 0 to 180, incrementing the angle each frame. Increment by a large number while the angle is less than 90, and a smaller number after that.
Here's the amended code:
Rem Project: Bump Mapping
Rem Created: 5/21/2008 3:28:02 PM
Rem ***** Main Source File *****
` Load Standards
Sync On
Sync Rate 30
Backdrop On
Hide Mouse
Autocam On
` Resolution
`Set Display Mode 1024, 768, 32
` Load the Images
Load Image "lead.bmp", 1
Load Image "leadBump.tga", 2
` Load an FX file
Load Effect "Phong.fx", 1, 0
` Make a Matrix
Make Matrix 1, 128, 128, 20, 20
Prepare Matrix Texture 1, 1, 1, 1
position matrix 1, 0.0, -1.0, 0.0
` Load a Gun
Make Object Cube 1, 10
Load Object "H-AK47-Static.x", 2
Load Image "ak47.bmp", 3
Load Image "ak47Bump.tga", 4
Scale Object 2, 250, 250, 250
Hide Object 1
` Texture the gun and Position it
Texture Object 2, 3
Disable Object ZDepth 2
` Offset all limbs in the gun the required amount
for i = 0 to 2
offset limb 2, i, limb offset x(2, i) + 0.45, limb offset y(2, i) - 0.2, limb offset z(2, i) + 0.6
next
` Make the Gun shiney
Set Light Mapping On 2, 4
Set Bump Mapping On 2, 4
Set Object Specular Power 2, 1000
set object specular 2, rgb(255,255,255)
Set Object Light 2, 1
`Set Object Effect 2, 1
` Customize the Ambient Light
Make Light 1
Hide Light 0
Show Light 1
Set Point Light 1, 30, 30, 30
Set Normalization On
OffsetAngle as float = 0.0
` Main loop
Do
` Camera Control
Control Camera Using ArrowKeys 0, 0.2, 5
` Position the gun relative to the camera
position object 2, camera position x(), camera position y(), camera position z()
rotate object 2, 0.0, camera angle y(), 0.0
` If the mouse is clicked, or the gun is already being moved around.
if OffsetAngle > 0.0 or mouseclick()
` If just starting, then throw the gun right back, otherwise allow it to move forward.
if OffsetAngle < 90.0
` Increase the increment for faster movement backwards, or lower it for slower movement
inc OffsetAngle, 30
else
` Increase the increment for faster movement forward, or lower it for slower movement
inc OffsetAngle, 12
endif
if OffsetAngle < 180.0
` Move the gun the required amount - Increase the multiplier to move the gun further
move object 2, 0.0 - sin(OffsetAngle) * 0.15
else
` We're back to the start, so disable movement until the mouse is clicked again
OffsetAngle = 0.0
endif
endif
` Update the screen
Sync
` End the loop
Loop
I've also moved the gun forward a little to allow the effect to be seen a little more clearly.