Fix NextUnitVector2
Fixed NextUnitVector2 method not producing a vector within a unit circle.
This commit is contained in:
@@ -297,8 +297,9 @@ namespace FlaxEngine.Utilities
|
||||
/// <returns>A random <see cref="Vector2"/>.</returns>
|
||||
public static Vector2 NextUnitVector2(this Random random, float radius = 1.0f)
|
||||
{
|
||||
var randomRadius = (float)random.NextDouble() * radius;
|
||||
return new Vector2((float)Math.Cos(random.NextDouble()) * randomRadius, (float)Math.Sin(random.NextDouble()) * randomRadius);
|
||||
float magnitude = (float)random.NextDouble() * radius;
|
||||
double randomDegree = random.NextDouble() * 360;
|
||||
return new Vector2((float)Math.Cos(randomDegree) * magnitude, (float)Math.Sin(randomDegree) * magnitude);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user