I'm back with a set of functions I found helpful a while back. I just re-wrote them in my own way(to fit my needs,Hamish McHaggis wrote this function.)
First,you need to setup the guns:
Setup_Weapons:
Type XYZ
x,y,z as float
endtype
type tWeap
ID as integer
Offset as xyz
Rotation as xyz
Scale as xyz
Bobangle as float
Lookangle as float
Turnangle as float
endtype
Global Dim gWeapon(0) as tWeap
Global NumWeapons as integer
Global GunHolder as integer
GunHolder = FreeObject()
hide object GunHolder
Global GunMesh as integer
GunMesh = FreeMesh()
make mesh from object GunMesh,GunHolder
add limb GunHolder,1,GunMesh
delete mesh GunMesh
return
Then you can add weapons
This function returns the index number of the weapon in
the array:
Function AddWeapon(model as string,x#,y#,z#,rx#,ry#,rz#,sx#,sy#,sz#)
array insert at bottom gWeapon(0)
inc NumWeapons
w = NumWeapons
gWeapon(w).id = FreeObject()
load object model,gWeapon(w).id
rotate object gWeapon(w).id,rx#,ry#,rz#
fix object pivot gWeapon(w).id
scale object gWeapon(w).id,sx#,sy#,sz#
disable object zdepth gWeapon(w).id
glue object to limb gWeapon(w).id,GunHolder,1
HideAllWeapons()
endfunction w
Then a few functions to help along the way:
Function HideAllWeapons()
for x = 1 to NumWeapons
HideWeapon(x)
next x
endfunction
Function HideWeapon(id as integer)
hide object gWeapon(id).id
endfunction
Function FreeObject()
repeat
inc i
until object exist(i) = 0
endfunction i
Function FreeMesh()
repeat
inc i
until mesh exist(i) = 0
endfunction i
Then you'll wanna update the weapons for the swaying effect. You simply tell it which weapon to update:
Function UpdateWeapon(weapon as integer)
xangle# = wrapvalue(xangle#+mousemovey()*0.2)
yangle# = wrapvalue(yangle#+mousemovex()*0.2)
gWeapon(weapon).Bobangle = curveangle(0,gWeapon(weapon).Bobangle,10)
gWeapon(weapon).Turnangle = curveangle(wrapvalue(mousemovex()),gWeapon(weapon).Turnangle,10)
gWeapon(weapon).Lookangle = curveangle(wrapvalue(mousemovey()),gWeapon(weapon).Lookangle,10)
Offset limb GunHolder,1,gWeapon(weapon).offset.x+sin(gWeapon(w).Bobangle),gWeapon(weapon).offset.y+abs(cos(gWeapon(weapon).Bobangle)),gWeapon(weapon).offset.z
Rotate limb GunHolder,1,gWeapon(weapon).Lookangle,gWeapon(weapon).Turnangle,0
x# = Camera position x()
y# = camera position y()
z# = camera position z()
position object GunHolder,x#,y#,z#
rotate object GunHolder,0,yangle#,0
pitch object down GunHolder,xangle#
endfunction
For a basic example:
sync on
sync rate 30
Gosub Setup_Weapons
Global weapon as integer
weapon = AddWeapon(YourWeaponFile$,0.0,0.0,0.0,0.0,5.0,0.0)
do
xangle# = wrapvalue(xangle#+mousemovey()*0.2)
yangle# = wrapvalue(yangle#+mousemovex()*0.2)
rotate camera xangle#,yangle#,0
UpdateWeapon(weapon)
sync
loop
Remember,that example is just to show how to work the functions. You'll need to use your own models and what not. And be sure to include the functions like I didn't
all ben needs is his band,his guitar,and his computer