示例#1
0
        protected virtual void CastRaysAbove()
        {
            if (!IsShootAboveRay)
            {
                return;
            }
            float rayLength = m_RayBoundsRectangel.height / 2 + RayOffset;

            m_VerticalRayCastFormLeft.x = m_RayBoundsRectangel.xMin;
            m_VerticalRayCastFormLeft.y = m_RayBoundsRectangel.center.y;

            m_VerticalRayCastToRight.x = m_RayBoundsRectangel.xMax;
            m_VerticalRayCastToRight.y = m_RayBoundsRectangel.center.y;

            if (m_AboveHitsStorge.Length != NumberOfVerticalRays)
            {
                m_AboveHitsStorge = new RaycastHit2D[NumberOfVerticalRays];
            }

            for (int i = 0; i < NumberOfVerticalRays; i++)
            {
                Vector2 rayOriginPoint = Vector2.Lerp(m_VerticalRayCastFormLeft, m_VerticalRayCastToRight, (float)(i / ((NumberOfVerticalRays - (float)1))));
                m_AboveHitsStorge[i] = PhyDebug.Raycast(rayOriginPoint, Vector2.up, rayLength, AboveLayerMask, Color.green, true);
            }
        }
示例#2
0
        /// <summary>
        /// 从中心轴向侧面发射射线
        /// 如果检测到墙或者斜坡,我们会检查它的角度,根据检查结果,判断是否移动
        /// </summary>
        protected virtual void CastRayToTheBackward()
        {
            if (!IsShootBackwardRay)
            {
                return;
            }
            //if (m_Speed == Vector3.zero) return;
            //向左
            float movementDirection = 1;

            if (m_Rigibody.velocity.x > 0)
            {
                //向右
                movementDirection = -1;
            }
            //水平方向射线长度
            float horizontalRayLength = m_RayBoundsRectangel.width / 2 + RayOffset;

            //计算水平射线分割低部值
            m_HorizontalRayCastFromBottom.x = m_RayBoundsRectangel.center.x;
            m_HorizontalRayCastFromBottom.y = m_RayBoundsRectangel.yMin;

            //计算水平射线分割顶部值
            m_HorizontalRayCastToTop.x = m_RayBoundsRectangel.center.x;
            m_HorizontalRayCastToTop.y = m_RayBoundsRectangel.yMax;
            //设置侧边碰撞信息集合
            if (m_BackwardHitsStorage.Length != NumberOfHorizontalRays)
            {
                m_BackwardHitsStorage = new RaycastHit2D[NumberOfHorizontalRays];
            }

            //发射NumberOfHorizontalRays 射线
            for (int i = 0; i < NumberOfHorizontalRays; i++)
            {
                Vector2 rayOriginPoint = Vector2.Lerp(m_HorizontalRayCastFromBottom, m_HorizontalRayCastToTop, (float)(i / (float)(NumberOfHorizontalRays - 1)));
                m_BackwardHitsStorage[i] = PhyDebug.Raycast(rayOriginPoint, movementDirection * (Vector2.right), horizontalRayLength, SidesLayerMask, Color.blue, true);
            }
        }
示例#3
0
        private void RayCastFloor()
        {
            if (!m_Attack)
            {
                m_LineRender.SetPosition(1, m_LineStartPos.position);
                return;
            }
            m_LineRenderMaterial.SetTextureOffset("_MainTex", new Vector2(m_Angle * 10, 0));
            Vector3 dir = Vector3.one;

            if (m_Dir == 1)
            {
                m_Angle = m_Angle + m_AngleSpeed * Time.deltaTime;
                Quaternion rot = Quaternion.AngleAxis(m_Angle, Vector3.forward);
                dir = rot * Vector3.down;
            }
            else
            {
                m_Angle = m_Angle - m_AngleSpeed * Time.deltaTime;
                Quaternion rot = Quaternion.AngleAxis(m_Angle, Vector3.forward);
                dir = rot * Vector3.down;
            }

            RaycastHit2D hit = PhyDebug.Raycast(m_LineStartPos.position, dir, 10, m_LineMask, Color.red);

            if (hit.distance > 0)
            {
                m_LineRender.SetPosition(1, hit.point);
                m_HitPoint = hit.point;
                if (m_AttackRole)
                {
                    RoleCtrl ctrl = hit.collider.GetComponent <RoleCtrl>();
                    if (ctrl != null)
                    {
                        if (Vector2.Dot(transform.position - ctrl.transform.position, ctrl.transform.right) > 0)
                        {
                            ctrl.ToHurt(5, chandDir: true);
                        }
                        else
                        {
                            ctrl.ToHurt(5);
                        }
                        m_AttackRole = false;
                    }
                }
            }
            if (m_Dir == 1)
            {
                if (m_Angle >= 90)
                {
                    m_Attack = false;
                    //StartCoroutine("EndAttack");
                }
            }
            else
            {
                if (m_Angle <= -90)
                {
                    m_Attack = false;
                    //StartCoroutine("EndAttack");
                }
            }
        }