コード例 #1
0
ファイル: U_Brain.cs プロジェクト: KaperDonjon/TNH
    bool LF_CheckMoveSpace(Unit Mover, float HorDir)
    {
        float CheckRad  = Mover.mov.BaseRad;
        float CheckDist = 5f;

        RaycastHit2D[] AllHits     = Physics2D.CircleCastAll(Mover.pos + Vector3.up * CheckRad * 1.05f, CheckRad, Vector3.right * HorDir, CheckDist);
        RaycastHit2D   ClossestHit = new RaycastHit2D();

        ClossestHit.distance = CheckDist * 2f;

        foreach (RaycastHit2D GoHit in AllHits)
        {
            Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>();
            if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Mover)
            {
                if (GoHit.distance < ClossestHit.distance)
                {
                    ClossestHit = GoHit;
                }
            }
        }

        TempToolPoint = ClossestHit.point;
        bool rezult = false;

        if (Mathf.Abs(Mover.pos.x - ClossestHit.point.x) > Mover.mov.BaseRad * 2f || ClossestHit.normal.y > 0.1f)
        {
            rezult = true;
        }

        return(rezult);
    }
コード例 #2
0
ファイル: U_Brain.cs プロジェクト: KaperDonjon/TNH
    bool LF_CheckStepForHole(Unit Stepper, float MovDir)
    {
        bool  rezult        = false;
        float CheckStepDist = Stepper.mov.BaseRad * 4f;

        RaycastHit2D[] AllHits     = Physics2D.CircleCastAll(Stepper.pos + Vector3.up * Stepper.mov.BaseRad + Vector3.right * MovDir * CheckStepDist, Stepper.mov.BaseRad, Vector3.down, Stepper.prm.MaxJumpHeight * 1.2f);
        RaycastHit2D   ClossestHit = new RaycastHit2D();

        ClossestHit.distance = Stepper.prm.MaxJumpHeight * 2f;

        foreach (RaycastHit2D GoHit in AllHits)
        {
            Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>();
            if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Stepper)
            {
                if (GoHit.distance < ClossestHit.distance)
                {
                    ClossestHit = GoHit;
                }
            }
        }

        if (ClossestHit.distance > 0.9f * Stepper.prm.MaxJumpHeight)
        {
            rezult = true;
        }

        return(rezult);
    }
コード例 #3
0
ファイル: U_Brain.cs プロジェクト: KaperDonjon/TNH
    float LF_CheckHoleSize(Unit Jumper, float HorDir)
    {
        float CheckRad = 0.1f;

        RaycastHit2D[] AllHits     = Physics2D.CircleCastAll(Jumper.pos, CheckRad, Vector3.right * HorDir, Jumper.prm.MaxJumpDist * 1.5f);
        RaycastHit2D   ClossestHit = new RaycastHit2D();

        ClossestHit.distance = Jumper.prm.MaxJumpDist * 2f;
        ClossestHit.point    = Jumper.pos + Vector3.right * HorDir * 99f;

        foreach (RaycastHit2D GoHit in AllHits)
        {
            Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>();
            if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper)
            {
                if (Mathf.Abs(GoHit.point.x - Jumper.pos.x) > Jumper.mov.BaseRad)
                {
                    if (GoHit.distance < ClossestHit.distance)
                    {
                        ClossestHit = GoHit;
                    }
                }
            }
        }

        float rezult = Mathf.Abs(ClossestHit.point.x - Jumper.pos.x);

        return(rezult);
    }
コード例 #4
0
ファイル: U_Brain.cs プロジェクト: KaperDonjon/TNH
    List <Vector3> LF_FindReachebleHeights(Vector3 CheckPoint, Unit Jumper)
    {
        RaycastHit2D[] AllHits  = Physics2D.CircleCastAll(Me.pos + Vector3.up * Me.mov.BaseRad, Me.mov.BaseRad * 0.8f, Vector3.up, Me.prm.MaxJumpHeight + Me.UnitHeight);
        RaycastHit2D   Clossest = new RaycastHit2D();

        Clossest.distance = (Me.prm.MaxJumpHeight + Me.UnitHeight) * 2f;
        Clossest.point    = Me.pos + Vector3.up * 100f;
        foreach (RaycastHit2D go in AllHits)
        {
            Solid2D WorkSolid = go.transform.GetComponent <Solid2D>();
            if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper)
            {
                if (go.distance < Clossest.distance)
                {
                    Clossest = go;
                }
            }
        }

        List <Vector3> rezult    = new List <Vector3>();
        float          CheckRad  = Jumper.UnitHeight * 0.5f;
        float          MaxHeight = Jumper.prm.MaxJumpHeight;



        AllHits = Physics2D.CircleCastAll(CheckPoint + Vector3.up * (MaxHeight + Jumper.UnitHeight), CheckRad, Vector3.down, MaxHeight * 1.5f);
        List <Vector3> TempPointList = new List <Vector3>();

        foreach (RaycastHit2D GoHit in AllHits)
        {
            Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>();
            if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper)
            {
                Vector3 GoPoint = GoHit.point;
                TempPointList.Add(GoPoint);
            }
        }

        foreach (Vector3 GoPoint in TempPointList)
        {
            bool PassPoint = true;

            Collider2D[] AllCols = Physics2D.OverlapCircleAll(GoPoint + Vector3.up * CheckRad * 1.05f, CheckRad);
            foreach (Collider2D GoCol in AllCols)
            {
                Solid2D WorkSolid = GoCol.transform.GetComponent <Solid2D>();
                if (WorkSolid != null)
                {
                    PassPoint = false;
                }
            }
            if (GoPoint.y + Me.UnitHeight * 1.1f > Clossest.point.y)
            {
                PassPoint = false;
            }

            if (PassPoint)
            {
                rezult.Add(GoPoint);
            }
        }

        return(rezult);
    }