Example #1
0
        public override List <ActorObj> CalculationHit(SkillData skilldata, GTargetInfo targetInfo)
        {
            float minDis = skilldata.MSV_AreaParam1 / 10.0f;
            float maxDis = skilldata.MSV_AreaParam2 / 10.0f;
            float w      = skilldata.MSV_AreaParam3 / 10.0f;

            Vector3 pos    = skilldata.IsAreaUseTarPos() ? targetInfo.m_vTarPos : targetInfo.m_vSrcPos;
            Vector3 dir    = targetInfo.m_vAimDir;
            Vector3 center = pos + dir * ((minDis + maxDis) / 2);

            SRect sRect = new SRect(center, maxDis - minDis, w);

            List <ActorObj> pActorList = ActorMgr.GetAllActor();

            if (pActorList.Count <= 0)
            {
                return(null);
            }
            List <ActorObj> list = new List <ActorObj>();

            foreach (ActorObj actor in pActorList)
            {
                if (actor == m_pLocalPlayer)
                {
                    continue;
                }
                ActorObj obj = (ActorObj)actor;
                if (obj.CollisionCom == null)
                {
                    continue;
                }
                for (int i = 0; i < obj.CollisionCom.GetShapeCount(); i++)
                {
                    SShapeData shp = obj.CollisionCom.GetShape(i);
                    if (shp != null)
                    {
                        SSphere sTarSphere = new SSphere(shp.Pos, shp.r);
                        if (GCollider.RectCollideCheck(sRect, sTarSphere, dir))
                        {
                            list.Add(actor);
                            break;
                        }
                    }
                }
            }
            return(list);
        }
Example #2
0
        /// <summary>
        /// 矩形判定
        /// 1、求圆心与中心向量(取绝对值)
        /// 2、求圆心与第一象限顶点距离
        /// 3、得到点到矩形边的距离(分离轴即为圆心与最近的一边的垂线段)
        /// 4、与半径对比即可
        /// </summary>
        /// <returns></returns>
        public static bool RectCollideCheck(SRect sRect, SSphere pTarget, Vector3 vDir)
        {
            Vector2 sRectPos   = new Vector2(sRect.center.x, sRect.center.z);
            Vector2 sTargetPos = new Vector2(pTarget.pos.x, pTarget.pos.z);

            Vector2 vAimDir   = new Vector2(1, 0);
            Vector2 vOpAimDir = new Vector2(0, 1);

            //test

            //取二维向量绝对值
            Vector2 offestVec = Vector2.Max((sRectPos - sTargetPos), (sTargetPos - sRectPos));
            //取第一象限顶点
            Vector2 vertexVec = vAimDir * (sRect.length * 0.5f) + vOpAimDir * (sRect.width * 0.5f);
            //当x,y某值小于0时即非垂直向量,归置为0即可
            Vector2 verticalVec = Vector2.Max(offestVec - vertexVec, Vector3.zero);

            return(verticalVec.sqrMagnitude <= pTarget.r * pTarget.r);
        }