矩形攻击范围


     /// <summary>
    /// 
    /// </summary>
    /// <param name="attacker">攻击者</param>
    /// <param name="attacked">被攻击者</param>
    /// <returns></returns>
    public bool RectAttackJudge(Transform attacker,Transform attacked,float forwardDistance, float rightDistance)
    {
        Vector3 deltaA = attacked.position - attacker.position;
        float forwardDotA= Vector3.Dot(attacker.forward, deltaA);
        if(forwardDotA>0&& forwardDotA<=forwardDistance)
        {
          if(  Mathf.Abs(Vector3.Dot(attacker.right,deltaA))<rightDistance)
            {
                return true;
            }
        }
        return false;
    }

转载自:https://blog.csdn.net/luncy_yuan/article/details/82469487

You may also like...

退出移动版