Exemplo n.º 1
0
 /// <summary>
 /// Gets a number of random points around a certain position within a min and max radius.
 /// </summary>
 /// <param name="position">Position to choose around</param>
 /// <param name="maxRadius">Maximum radius to get points around</param>
 /// <param name="minRadius">Minimum radius to get points around</param>
 /// <param name="maxPoints">Maximum number of points obtained</param>
 /// <returns>The random points obtained</returns>
 private Vector3[] GetPointsAround(Vector3 position, float maxRadius, float minRadius, int maxPoints)
 {
     Vector3[] points = new Vector3[maxPoints];
     for (int i = 0; i < maxPoints; i++)
     {
         points[i] = AuxiliarFunctions.PickRandomPosAroundPoint(position, maxRadius, terrainUsed, minRadius);
     }
     return(points);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates a position in the scene for a new basket raycasting to the floor from an initial posible position.
        /// Takes care of not being too close of an environment object.
        /// </summary>
        /// <param name="defaultPosition">A posible initial position</param>
        /// <returns>The calculated position</returns>
        private Vector3 CalculateNewBasketPosition(Vector3 defaultPosition)
        {
            RaycastHit hit;
            Vector3    targetLocation;

            // Check downwards or upwards to get a position in the floor
            if (Physics.Raycast(defaultPosition, Vector3.down, out hit, Mathf.Infinity, FloorMask) ||
                Physics.Raycast(defaultPosition, Vector3.up, out hit, Mathf.Infinity, FloorMask))
            {
                targetLocation = hit.point;
                // While not getting a position clear of nearby environment objects, keep looking for a position
                while (AuxiliarFunctions.CheckObjectsAround(targetLocation, checkObjectsRadius, EnvironmentMask))
                {
                    targetLocation = AuxiliarFunctions.PickRandomPosAroundPoint(hit.point, pickPointRadius);
                }
            }
            else
            {
                Debug.LogError("NoFloortHit");
                targetLocation = new Vector3(defaultPosition.x, 0f, defaultPosition.z);
            }
            return(targetLocation);
        }