> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinemation.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Recoil Animation

> Learn how to configure procedural recoil animation in the Tactical Shooter Pack for Unity.

## Recoil Animation component

**Recoil Animation** is a component that generates smooth and fluid firing animations at runtime:

<Frame caption={"Recoil Animation component."}>
  <img src="https://mintcdn.com/kinemation/JeFzhKqzivzKAwnI/images/cas/0bfe6da2058e6100c172.png?fit=max&auto=format&n=JeFzhKqzivzKAwnI&q=85&s=fc7af18c7e9d96efac988c63f351e8cc" alt="Recoil Animation component in the Unity Inspector" width={413} data-path="images/cas/0bfe6da2058e6100c172.png" />
</Frame>

This component has 3 methods that need to be called in the shooting code.

## Recoil Anim Data

Recoil parameters are defined in the RecoilAnimData — a Scriptable Object that you can create via **right-click ▸ Create ▸ KINEMATION ▸ Procedural Recoil ▸ Recoil Data**:

<Frame caption={"Recoil Anim Data properties."}>
  <img src="https://mintcdn.com/kinemation/bY9DOuHDrQwriMA1/images/cas/dfbbcc39780f40ab8b39.png?fit=max&auto=format&n=bY9DOuHDrQwriMA1&q=85&s=dd57960b5794e78d9793108869255cb6" alt="Recoil Anim Data properties in the Unity Inspector" width={404} data-path="images/cas/dfbbcc39780f40ab8b39.png" />
</Frame>

<Tabs>
  <Tab title="Recoil targets">
    * **Pitch** - max and min values for the pitch (up) rotation

    * **Roll** - max and min values for the roll rotation.

    * **Yaw** - max and min values for the yaw (right) rotation.

    **Roll and Yaw** components are Vector4. That's because of the way random values are calculated:

    Minimum value for **Roll and Yaw** is a random value in \[X;Y] range, while the maximum value is in \[Z;W] range.

    **Aim Rot** and **Aim Loc** define multipliers for each rotation and translation. Applied when aiming.
  </Tab>

  <Tab title="Smoothing">
    **Smooth Rot/Loc** - defines interpolation speed for rotation and translation. Not applied if 0. **Extra Rot/Loc** - multipliers applied in auto/burst mode only.
  </Tab>

  <Tab title="Layers">
    Noise layer is a continuous 2D movement that simulates inaccuracy when firing.

    * **Noise X/Y** - max and min values for position offsets along X and Y axes (right and up movement).

    * **Noise Accel** - acceleration speed.

    * **Noise Damp** - damping speed. **Noise Scalar** - aiming multiplier.

    Pushback layer is applied on the first shot of the auto or burst fire mode.

    * **Push Amount** - maximum value of the pushback.

    * **Push Accel** - acceleration speed.

    * **Push Damp** - damping speed.
  </Tab>

  <Tab title="Miscellaneous">
    * **Hip Pivot Offset** - weapon pivot offset when hip firing.

    * **Aim Pivot Offset** - weapon pivot offset when aiming.

    * **Smooth Roll** - if enabled, the sign of a random value for roll will change every shot.

    * **Play Rate** - the speed of the recoil animation.

    * **Recoil Curves** - normalized animation curves.
  </Tab>
</Tabs>

## Recoil curves

There are 4 Vector curves in the data asset. Each curve animates the rotation or translation when auto or single firing.

<Frame caption={"Example semi curves."}>
  <img src="https://mintcdn.com/kinemation/JeFzhKqzivzKAwnI/images/cas/5d83dd34d454453a9139.png?fit=max&auto=format&n=JeFzhKqzivzKAwnI&q=85&s=fd9c813ce7caa26fb3520c9f5a3684e0" alt="Example semi-fire recoil curves" width={404} data-path="images/cas/5d83dd34d454453a9139.png" />
</Frame>

<Tip>
  All curves must start and end with zero.
</Tip>

Here's the difference between auto and semi curves:

<Tabs>
  <Tab title="Auto curve">
    <img src="https://mintcdn.com/kinemation/JeFzhKqzivzKAwnI/images/cas/4b8677ee01eb5e5347a4.png?fit=max&auto=format&n=JeFzhKqzivzKAwnI&q=85&s=62b9c2b08dd6077c58725ab6997935ae" alt="Example automatic-fire recoil curve" width={563} data-path="images/cas/4b8677ee01eb5e5347a4.png" />
  </Tab>

  <Tab title="Semi curve">
    <img src="https://mintcdn.com/kinemation/JeFzhKqzivzKAwnI/images/cas/2f5c6711270652c5a543.png?fit=max&auto=format&n=JeFzhKqzivzKAwnI&q=85&s=d4d771d364e2dbb74287a529489513b3" alt="Example semi-fire recoil curve" width={562} data-path="images/cas/2f5c6711270652c5a543.png" />
  </Tab>
</Tabs>

Curves are almost identical. The only difference is that the Auto curve value is very close to zero at some point. This point is the delay between shots.

> For example, a fire rate of 600 RPM has a delay of 0.1 seconds between shots. All auto curves must be close to 0 at 0.1 seconds.

<Info>
  When auto or burst mode is enabled, the curve length is set to the fire delay. The auto or burst curve is cropped to the delay between shots.
</Info>

## Apply recoil animation

Add the Recoil Animation component to the character's prefab and apply the changes. Then, add a **Modify Bone** modifier to the Procedural Animation settings and bind the recoil `OutRot` and `OutLoc` values:

<Frame caption={"Modify Bone and Recoil Animation."}>
  <img src="https://mintcdn.com/kinemation/zfSCxGML5W5QOyC1/images/cas/a3c41e928685ba0cf560.png?fit=max&auto=format&n=zfSCxGML5W5QOyC1&q=85&s=4dc32d48848714826f68b677474bf62e" alt="Modify Bone modifier bound to Recoil Animation outputs" width={390} data-path="images/cas/a3c41e928685ba0cf560.png" />
</Frame>
