Recoil
The Recoil
component handles procedural recoil animations using rotation. It reacts to each shot and resets over time, allowing natural, dynamic aiming motion.
Summary
This component:
- Applies local rotation to simulate vertical and horizontal recoil
- Uses animation curves (
MinMaxCurve
) to vary recoil patterns - Smoothly returns to default position using
Lerp
Fields
Field | Type | Description |
---|---|---|
speed | float | How quickly recoil progresses per shot. |
resetSpeed | float | How quickly the recoil resets to neutral. |
recoilVertical | MinMaxCurve | Vertical (pitch) rotation applied per shot. |
recoilHorizontal | MinMaxCurve | Horizontal (yaw) rotation applied per shot. |
Public Methods
Method | Description |
---|---|
void Evaluate(float fireRate) | Applies new recoil based on fire rate and curve values. |
void Reset() | Resets recoil step so it starts fresh next time. |
Internal Behavior
Evaluate()
is called by the weapon system when a shot is fired.- Rotation is applied using
Quaternion.Euler()
, scaled using fire rate and noise. Update()
smooths rotation back to default every frame.
Example Use
recoil.Evaluate(barrel.fireRate);
Note
Recoil is applied to the GameObject this script is attached to. You can make it a pivot child of the weapon model to isolate >motion.
Tip
You can use MinMaxCurve to randomize or control recoil escalation with time or shot count.
See Also Weapon