diff --git a/OpenRA.Game/Effects/Bullet.cs b/OpenRA.Game/Effects/Bullet.cs index dd72496ca6..a7850babd9 100755 --- a/OpenRA.Game/Effects/Bullet.cs +++ b/OpenRA.Game/Effects/Bullet.cs @@ -57,9 +57,7 @@ namespace OpenRA.Effects Info = info; Args = args; - VisualDest = args.dest + new int2( - args.firedBy.World.CosmeticRandom.Next(-10, 10), - args.firedBy.World.CosmeticRandom.Next(-10, 10)); + VisualDest = args.dest + (10 * args.firedBy.World.CosmeticRandom.Gauss2D(1)).ToInt2(); if (Info.Image != null) { diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index d6757e329b..4ce3391662 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -217,5 +217,18 @@ namespace OpenRA { return w.WorldActor.Info.Traits.WithInterface(); } + + public static float Gauss1D(this Thirdparty.Random r, int samples) + { + var xs = Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1); + return xs.Sum() / samples; + } + + // Returns a random offset in the range [-1..1,-1..1] with a separable + // Gauss distribution with 'samples' values taken for each axis + public static float2 Gauss2D(this Thirdparty.Random r, int samples) + { + return new float2(Gauss1D(r, samples), Gauss1D(r, samples)); + } } }