Ejemplo n.º 1
0
        public static Vector2 RandomRadial2DUnitVector(RandomFloatProvider random, float distance)
        {
            float angle  = random.getFloat(0, 2 * Mathf.PI);
            float radius = Mathf.Sqrt(distance);

            return(new Vector2(
                       radius * Mathf.Cos(angle),
                       radius * Mathf.Sin(angle)
                       ));
        }
Ejemplo n.º 2
0
        public static Vector3 RandomNavSphere(RandomFloatProvider random, Vector3 origin, float distance, int layermask)
        {
            Vector3 randomDirection = RandomPointInSphere(random) * distance;

            randomDirection += origin;

            NavMeshHit navHit;

            NavMesh.SamplePosition(randomDirection, out navHit, distance, layermask);

            return(navHit.position);
        }
Ejemplo n.º 3
0
        //https://karthikkaranth.me/blog/generating-random-points-in-a-sphere/
        public static Vector3 RandomPointInSphere(RandomFloatProvider randomProvider)
        {
            var u     = randomProvider.getFloat(1f);
            var v     = randomProvider.getFloat(1f);
            var theta = u * 2.0 * Math.PI;
            var phi   = Mathf.Acos(2f * v - 1f);
            // cube root to give even distribution, rather than clumping to origin
            var r        = Mathf.Pow(randomProvider.getFloat(1f), 1f / 3f);
            var sinTheta = Math.Sin(theta);
            var cosTheta = Math.Cos(theta);
            var sinPhi   = Math.Sin(phi);
            var cosPhi   = Math.Cos(phi);
            var x        = r * sinPhi * cosTheta;
            var y        = r * sinPhi * sinTheta;
            var z        = r * cosPhi;

            return(new Vector3((float)x, (float)y, (float)z));
        }
Ejemplo n.º 4
0
 public static Quaternion RandomRotation(RandomFloatProvider randomProvider)
 {
     return(Quaternion.Euler(randomProvider.getFloat(0, 360), randomProvider.getFloat(0, 360), randomProvider.getFloat(0, 360)));
 }