Example #1
0
        /// <summary>
        /// Casts a ray back. Returns true if a hit is detected.
        /// </summary>
        /// <param name="_start"></param>
        /// <param name="_dist"></param>
        /// <param name="_debug"></param>
        /// <returns></returns>
        public static bool CastRight(this Transform _start, float _dist, bool _debug = false)
        {
            if (_debug)
            {
                Debug.DrawRay(_start.position, _start.right, BaneTools.Color255(255, 0, 0), 0, false);
            }

            return(Physics.Raycast(_start.position, _start.right, _dist) ? true : false);
        }
Example #2
0
        /// <summary>
        /// Casts a ray back. Returns true if a hit is detected.
        /// </summary>
        /// <param name="_start"></param>
        /// <param name="_dist"></param>
        /// <param name="_debug"></param>
        /// <returns></returns>
        public static bool CastBackward(this Transform _start, float _dist, bool _debug = false)
        {
            if (_debug)
            {
                Debug.DrawRay(_start.position, -_start.forward, BaneTools.Color255(0, 0, 255), 0, false);
            }

            return(Physics.Raycast(_start.position, -_start.forward, _dist) ? true : false);
        }
Example #3
0
        public static bool ViewNotObstructed(Transform _start, Transform _target, bool _debug)
        {
            //Stores the visibility checks
            bool clearFlag = false;

            //Adds the offsets provided in the Inspector to reach each side.
            Vector3 leftSide = _start.position;

            //Getting the direction from the correct side to the target
            Vector3 leftDir = _target.position - leftSide;

            //Defines the raycast hit variables
            RaycastHit leftHit;

            if (_debug)
            {
                //Draw Rays so they can be seen in Scene View
                Debug.DrawRay(leftSide, leftDir, BaneTools.Color255(255, 255, 0), 1, false);

                if (Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude))
                {
                    Debug.Log("Ray hit " + leftHit.collider.name);
                }
            }

            //Set flag to false if the raycast hits something, else set it to true
            if (Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude))
            {
                if (leftHit.collider.transform == _target)
                {
                    if (_debug)
                    {
                        Debug.Log("The view is not obstructed!");
                    }
                    clearFlag = true;
                }
            }
            else
            {
                clearFlag = false;
            }
            //clearFlag = Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude, ) ? false : true;

            //Debug.Log(clearFlag);

            //If all four flags are true, return true
            return(clearFlag);
        }
Example #4
0
        public static bool VewNotObstructed(Vector4 objectBounds, Transform _start, Transform _target, bool _debug)
        {
            //Stores the visibility checks
            Vector4 clearFlags = new Vector4(0, 0, 0, 0);

            //Adds the offsets provided in the Inspector to reach each side.
            Vector3 leftSide   = BaneMath.SplitAddedVector3(_start.position, +objectBounds.x, 0, 0);
            Vector3 rightSide  = BaneMath.SplitAddedVector3(_start.position, +objectBounds.y, 0, 0);
            Vector3 topSide    = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.z, 0);
            Vector3 bottomSide = BaneMath.SplitAddedVector3(_start.position, 0, +objectBounds.w, 0);

            //Getting the direction from the correct side to the target
            Vector3 leftDir   = _target.position - leftSide;
            Vector3 rightDir  = _target.position - rightSide;
            Vector3 topDir    = _target.position - topSide;
            Vector3 bottomDir = _target.position - bottomSide;

            //Defines the raycast hit variables
            RaycastHit leftHit;
            RaycastHit rightHit;
            RaycastHit topHit;
            RaycastHit botHit;

            if (_debug)
            {
                //Draw Rays so they can be seen in Scene View
                Debug.DrawRay(leftSide, leftDir, BaneTools.Color255(255, 255, 0), 1, false);
                Debug.DrawRay(rightSide, rightDir, BaneTools.Color255(0, 255, 255), 1, false);
                Debug.DrawRay(topSide, topDir, BaneTools.Color255(255, 0, 255), 1, false);
                Debug.DrawRay(bottomSide, bottomDir, BaneTools.Color255(0, 0, 255), 1, false);

                //if (Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude))
                //{
                //  Debug.Log("Left hit " + leftHit.collider.name);
                //}
            }

            //Set flag to false if the raycast hits something, else set it to true
            clearFlags.x = Physics.Raycast(leftSide, leftDir.normalized, out leftHit, leftDir.magnitude) ? 0 : 1;
            clearFlags.y = Physics.Raycast(rightSide, rightDir.normalized, out rightHit, rightDir.magnitude) ? 0 : 1;
            clearFlags.z = Physics.Raycast(topSide, topDir.normalized, out topHit, topDir.magnitude) ? 0 : 1;
            clearFlags.w = Physics.Raycast(bottomSide, bottomDir.normalized, out botHit, bottomDir.magnitude) ? 0 : 1;

            Debug.Log(clearFlags);

            //If all four flags are true, return true
            return(clearFlags == new Vector4(1, 1, 1, 1) ? true : false);
        }