gun animation

Blitz3D Forums/Blitz3D Programming/gun animation

panton(Posted 2008) [#1]
Hi there. can anybody give me an example for
how to animate a gun for a fps game, like when the player is walking, the gun moves up and down, and goes to the right and left.


Pirate(Posted 2008) [#2]
here is a couple of simple functions that might help...one is for the movement and the other for recoil...be sure to make wepmovecounter and recoilcounter global....this code was given to me by: bazza...

Function WepsMovement()

If WepMoveCounter<8         ;If the counter is less than 8
MoveEntity Shotgun,0,0,.04  ;Move the shotgun backward
EndIf

If WepMoveCounter>8         ;If the counter is greater than 8
MoveEntity Shotgun,0,0,-.04 ;Move the shotgun forward
EndIf

If WepMoveCounter=16        ;If the counter =16 then movement fully completed
WepMoveCounter=0            ;set the counter back to 0
Return                      ;Jump out of this function
EndIf
WepMoveCounter=WepMoveCounter+1 ;increse the counter

End Function


;Recoils the weapon when it's fired using another counter variable
Function Recoil()

If RecoilCounter<1         ;If the RecoilCounter is less then 1
MoveEntity Shotgun,0,0,-.5 ;Move the shotgun backward
EndIf
If RecoilCounter>1         ;If the RecoilCounter is grater then 1
MoveEntity Shotgun,0,0,.5  ;Move the shotgun forward
EndIf
If RecoilCounter=2          ;recoil completed
RecoilFlag=0                ;re-set the flag
RecoilCounter=0             ;and the counter
Return                      ;Jump out of this function
EndIf
ReCoilCounter=ReCoilCounter+1 ;Increase the counter

End Function



panton(Posted 2008) [#3]
Thank you!


Kryzon(Posted 2008) [#4]
One other easy way is to use Sin and Cos functions to slowly keep that "breathing-smooth-shaking-hands" movement when you stand still in a FPS game.
Increasing the processing angle by small factors so the motion is slow, and applying a kernel multiplier that stabilizes the strength of motion so that you'd get a nice slow motion. And change those variables when you start walking to stronger values.

TurnEntity Arms,Sin(angle)*.05,Cos(angle)*.5,0

angle# = angle+.5 : If angle = 360 Then angle = 0