Recoil Component

The Recoil component is responsible for simulating the visual and functional kickback of a weapon when fired. It can be used in two main ways:

  • ๐ŸŽฏ Random recoil: Generates a light randomized movement in both X and Y axes
  • ๐ŸŽฏ Spray pattern recoil: Follows a progressively randomized path between two animation curves

This component is highly versatile and can be used to create subtle kickback, chaotic recoil, or tight predictable spray patterns like those found in competitive shooters.

๐Ÿงฑ Hierarchy Setup

To use recoil properly in your weapon prefab, follow this structure:

  flowchart TD
    A[Weapon Root] --> B(Recoil) 
    B --> C(Weapon Model)

Note

The Recoil object must be the second GameObject after the root, and all parts of the weapon should be children of it. The recoil system will apply positional and rotational offsets to this transform.

Note

Make sure that the tansform is centered to 0

๐ŸŽฎ How It Works

Each time a shot is fired:

  • A new offset is calculated based on the recoil mode (random or spray)
  • The recoil object moves accordingly
  • Over time, the transform resets back to its neutral position using the Reset Speed

๐Ÿ“ Inspector Overview

Random Recoil Mode

This is the simplest configuration. The system will generate a random value between min and max values for both vertical and horizontal recoil.

FieldDescription
SpeedHow fast the recoil motion happens when firing
Reset SpeedHow quickly the weapon returns to its original position
Recoil VerticalRange of vertical kickback (Y axis)
Recoil HorizontalRange of horizontal drift (X axis)

Spray Pattern Mode

If Recoil Vertical and Recoil Horizontal are set using curves, the system will follow a predefined spray path.

  • Each axis uses two curves: a min and max range
  • A random point between the two curves is chosen per shot
  • The index along the curve increases with each shot to simulate escalating spray

Tip

This method gives you tight artistic control over recoil paths, useful for skill-based shooting mechanics.

๐Ÿ”ฌ In-Game Result

Hereโ€™s an example of a spray pattern applied to a grenade rifle:

Each bullet hits along a progressively randomized path, creating a unique, learnable spread.

๐Ÿ“ Summary

  • Place the recoil component on a child object above your weapon model
  • Choose between random or spray by how you configure the curves
  • Control sharpness with Speed and how quickly it stabilizes with Reset Speed