# Recoil Animation

## How Does It Work?

The **PRAS (Procedural Recoil Animation System)** uses an advanced, yet simple way to generate realistic recoil. The system takes Vector Curves for translation and rotation, plays them in runtime, and uses curve values as interpolation alphas to reach the randomly generated targets.

> RecoilAnimation = Lerp(0f, TargetValue, CurveValue)

where **Target Value** is randomly generated when a shot is fired.

<figure><img src="https://3651122009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmWlhCRI70uShLRiOey3T%2Fuploads%2FbGyBFT8oA2snyTlu8Z2W%2Fimage.png?alt=media&#x26;token=c597fb21-26e5-4a41-a303-be413e5b20f8" alt="" width="563"><figcaption><p>Example recoil curve.</p></figcaption></figure>

Recoil curves should be in the range \[-1;1], so a curve value can be used as an interpolation alpha. The curve peaks at 1 and then goes down to 0 with some oscillation.

{% hint style="success" %}
**Tip**: because curves are much simpler in comparison to other methods (e.g. spring interpolation), the recoil animation is frame-rate independent.
{% endhint %}

## Single and Auto Fire

**Recoil Data** is an asset, which contains all information about the recoil animation. This includes curves and other settings:

<figure><img src="https://3651122009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmWlhCRI70uShLRiOey3T%2Fuploads%2Fuf3hCnpZyMVd7Gru8iuJ%2Fimage.png?alt=media&#x26;token=a0bf6c2d-e352-43b1-a343-f447802bd471" alt="" width="383"><figcaption><p>Curve section in the Recoil Data.</p></figcaption></figure>

To create a new **Recoil Data**, right-click and go to <mark style="background-color:purple;">**Miscellaneous -> Data Asset -> Recoil Data**</mark>. This asset includes 4 *Vector Curves* in total: 2 for translation and 2 for rotation. The PRAS has 2 main fire modes:

* Single
* Auto/Burst (there's no technical difference animation-wise)

{% hint style="success" %}
**Tip**: we use different curves for single and auto fire because of animation quality. If we use single-fire curves when auto-firing, the animation will look choppy. To make it look smoother and more fluid we use a different set of curves.
{% endhint %}

Let's compare an example single and auto fire curve:

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

<figure><img src="https://3651122009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmWlhCRI70uShLRiOey3T%2Fuploads%2Fj9OuQEgdKvPOsUFSmIo0%2Fimage.png?alt=media&#x26;token=1956567a-ad4c-4338-9664-9a3ea89beab8" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Auto/Burst" %}

<figure><img src="https://3651122009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmWlhCRI70uShLRiOey3T%2Fuploads%2FS656FcC1900ZLIaUsT2X%2Fimage.png?alt=media&#x26;token=949f1a80-ef7b-4791-a2e3-5cbccb400760" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

The curves are almost identical! The only difference is that auto curve values are very close to 0 at some time - this time equals the fire rate of a weapon (in this case 600RPM = 0.1s). This will ensure that the weapon's main muzzle climbing will be fully preserved when auto-firing.

{% hint style="danger" %}
**Tip**: regardless of a fire mode, the first shot is **always** a single fire shot.
{% endhint %}
