- Create a Spatial node, move it to where your hand should be
- Place your Gun Model as a child of the Spatial
- Give the Spatial node the Gun Sway script
- (Optional) for rolling motion when moving left or right, set
input_direction
to the direction of the joystick or keyboard input
LIMITS
controls how far the gun swings on each axis (see below)return_speed
controls how quickly it interpolates back to the rest positionsway_speed
controls how quickly the gun sways when your mouse movesmouse_sensitivity
controls how sensitive mouse inputs are
Everytime the gun is to be rotated, the rotation amount is diminshed by the following graph: The effect of the sway decreases as the gun swings outwards further so that it converges to a maximum limit
This is where the following export variable is used:
export(Vector3) var LIMITS := Vector3(1.0, 1.0, 1.0)
Each value of LIMITS
controls how much the Gun Sways on each axis.
Note that LIMITS.z
actually controls the roll of the gun when moving. Rolling only works if you pass a value to input_direction
If you like my stuff, consider a sub to my channel?