menu_bookDocumentation

s&box Vector3.WithAimCone: Direction spread

calendar_today May 12, 2026 schedule ~1 min read person PatrickJr verified 50

Vector3.WithAimCone Extension Method

The WithAimCone extension method adds random spread to a direction vector, useful for bullet spread, projectile dispersion, and other aim-based randomization.

Extension Methods

CSHARP
public static class Extensions
{
    public static Vector3 WithAimCone(this Vector3 direction, float degrees)
    {
        var angle = Rotation.LookAt(direction);
        angle *= new Angles(Game.Random.Float(-degrees / 2.0f, degrees / 2.0f), Game.Random.Float(-degrees / 2.0f, degrees / 2.0f), 0);
        return angle.Forward;
    }

    public static Vector3 WithAimCone(this Vector3 direction, float horizontalDegrees, float verticalDegrees)
    {
        var angle = Rotation.LookAt(direction);
        angle *= new Angles(Game.Random.Float(-verticalDegrees / 2.0f, verticalDegrees / 2.0f), Game.Random.Float(-horizontalDegrees / 2.0f, horizontalDegrees / 2.0f), 0);
        return angle.Forward;
    }
}

Parameters

WithAimCone(Vector3 direction, float degrees)

WithAimCone(Vector3 direction, float horizontalDegrees, float verticalDegrees)

Usage

CSHARP
// Add 5 degrees of spread in all directions
var spreadDirection = aimDirection.WithAimCone(5.0f);

// Add different horizontal and vertical spread
var spreadDirection = aimDirection.WithAimCone(horizontalDegrees: 10.0f, verticalDegrees: 2.0f);

// Use for bullet spread
var bulletDirection = player.EyeRotation.Forward.WithAimCone(weapon.Spread);

Notes

  • Uses Game.Random.Float for random spread generation
  • Spread is symmetric around the base direction
  • Returns a normalized direction vector
  • Commonly used in weapon systems for bullet spread
  • The two-parameter version allows asymmetric spread (wider horizontal than vertical, or vice versa)
Was this helpful?