# Recoil Animation

The recoil system in the framework consists of these 3 main components:

* Recoil Animation
* Recoil Pattern
* Camera Shake

In this chapter we will cover the procedural animations, and how to create that really nice and fluid recoil.

## Component

Make sure to add the RecoilAnimation component to your character. This component will generate that smooth recoil in realtime, which will be applied by the [additive-layer](https://kinemation.gitbook.io/scriptable-animation-system/fundamentals/animator-layers/additive-layer "mention").

This component has 3 main methods:

```csharp
public void Play(); // Fired a gun, call it every shot.
```

```csharp
public void Stop(); // Call it when fire key is released.
```

{% code overflow="wrap" %}

```csharp
// Call this when a gun is equipped.
void Init(RecoilAnimData data, float fireRate, FireMode newFireMode);
```

{% endcode %}

## Basic Properties

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FuyZlmj5KmDDLGZaR2GQI%2Fimage.png?alt=media&#x26;token=a7c9706c-a8a0-4f60-8c9a-12b0cc4e1d2e" alt="" width="404"><figcaption></figcaption></figure>

This asset contains animation curves and values for the recoil solver:

{% 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 maximum value is in \[Z;W] range.

**Aim Rot** and **Aim Loc** define multipliers for each rotation and transaltion. Applied when aiming.
{% endtab %}

{% 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.
{% endtab %}

{% tab title="Layers" %}

* 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 multipler.

Pushback Layer 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.
  {% endtab %}

{% tab title="Misc" %}
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.
{% endtab %}
{% endtabs %}

## Recoil Curves

There are 4 Vector curves in the data asset, where each Vector curve is designed to animate the rotation or translation when auto/single firing.

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FrGBTklYL9tki7KPIsgkr%2Fimage.png?alt=media&#x26;token=c056ef85-9a4b-44ab-bf52-0228200a1df2" alt="" width="404"><figcaption><p>Example semi curves.</p></figcaption></figure>

{% hint style="info" %}
**Tip:** all curves must start and end with zero!
{% endhint %}

Here's the difference between auto and semi curves:

{% tabs %}
{% tab title="Semi" %}

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2F72IMzMlR69d6gbWImV3d%2Fimage.png?alt=media&#x26;token=c3b25639-cead-4fc2-b5ed-283f56102054" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Auto" %}

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FjcP4lOGkeZtZYqMaIsYN%2Fimage.png?alt=media&#x26;token=5509b438-544b-4b25-a94c-7fe5639d1f10" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

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

> Example: let's say our fire rate is 600 RPM, then the delay between shots is 0.1s. This means, that all auto curves must be close to 0 at 0.1s time.

{% hint style="success" %}
**Tip:** this is required for the auto solver to work properly. When auto/burst mode is enbaled, the curve length is set to the fire delay (see our example above). So, the length of the auto or burst curve gets cropped to the fire delay between shots.
{% endhint %}
