RecoilPattern.cs

Data container for a weapon recoil pattern. Stores an ordered list of cumulative aim offsets as Vector2 points and exposes configuration for approach and recovery speeds and editor scaling. Provides a helper to get a point for a given shot index.

using System;
using System.Collections.Generic;

public sealed class RecoilPattern
{
	/// <summary>Ordered cumulative aim offsets in normalized screen units (center origin, +Y = up).</summary>
	[Property] public List<Vector2> Points { get; set; } = new();

	/// <summary>How fast current recoil moves toward the target pattern point.</summary>
	[Property] public float ApproachSpeed { get; set; } = 25f;

	/// <summary>How fast recoil decays back to center when not firing.</summary>
	[Property] public float RecoverySpeed { get; set; } = 8f;

	/// <summary>Editor canvas edge as a screen fraction from center (0.06 = 6%). Used to scale the pattern editor.</summary>
	[Property] public float MaxExtent { get; set; } = 0.06f;

	public bool HasPoints => Points is { Count: > 0 };

	public Vector2 GetPoint( int shotIndex )
	{
		if ( !HasPoints )
			return Vector2.Zero;

		return Points[Math.Clamp( shotIndex, 0, Points.Count - 1 )];
	}
}