#Adding a weapon sway

1 messages · Page 1 of 1 (latest)

velvet pagoda
#

How can I add sway? Has anyone implemented it?

untold bay
velvet pagoda
#

This is an fps animation pack

untold bay
# velvet pagoda This is an fps animation pack

Okay, so you can write your own sway calculation logic, and then apply the final value to the ik_hand_gun bone in Late Update - this bone controls the weapon and hands poses. You'll also need to insert that logic in the FPSPlayer or Procedural Animation scripts, depending on what exactly you are using

velvet pagoda
untold bay
# velvet pagoda

You need to place that logic inside the FPS Player or Procedural Animation component, I suggest taking a look at how it's implemented in the Late Update method

velvet pagoda
untold bay
# velvet pagoda Now there are some very strong twitches

This will not work, because transform is updated every single frame, so it won't be accumulated. Instead, you need to create a variable, call it _swayRotation and then modify it instead. Finally, accumulate the rotation result: transform.rotation *= _swayRotation

#

Also, do not use the Slerp function this way. Instead, use this code snippet:

float alpha = KMath.ExpDecayAlpha(interpolationSpeed, Time.deltaTime);
_swayRotation.rotation = Quaternion.Slerp(_swayRotation, targetRotation, alpha);
transform.rotation *= _swayRotation;