コード例 #1
0
ファイル: MoveState.cs プロジェクト: Kobakat/Super-Oiram
    protected virtual void CheckForBlockCollisions(UnityMover m)
    {
        UnityBlock b   = null;
        Vector2    vec = Vector2.zero;

        float dst = 10; //initialize this to an unimportant value

        m.mover.unitTouchCount  = 0;
        m.mover.blockTouchCount = 0;
        foreach (UnityBlockChunk chunk in m.unityBlockChunksCurrentlyIn)
        {
            foreach (UnityBlock uBlock in chunk.unityBlocks)
            {
                if (Utility.Intersectcs(m.entity.rect, uBlock.block.rect) && m.gameObject.activeSelf)
                {
                    Vector2 newVec = m.entity.position - uBlock.block.position;

                    float newDst = newVec.magnitude;

                    if (newDst < dst)
                    {
                        vec = newVec;
                        dst = newDst;
                        b   = uBlock;
                    }

                    m.mover.unitTouchCount++;
                    m.mover.blockTouchCount++;
                }
            }
        }

        if (m.mover.blockTouchCount > 0)
        {
            float minAngle = Utility.MinDropAngle(m.entity.rect, b.block.rect);

            minAngle = 90 - minAngle;

            float angle = Vector2.Angle(vec, Vector2.up);

            if (angle < minAngle)
            {
                m.HitTop(b);
            }
            else if (angle >= minAngle && angle <= 180 - minAngle)
            {
                m.HitSide(b, vec.x);
            }
            else
            {
                m.HitBottom(b);
            }

            Debug.DrawRay(b.block.rect.position, vec);
        }
    }
コード例 #2
0
ファイル: MoveState.cs プロジェクト: Kobakat/Super-Oiram
    public virtual void CheckForCollisionWithOtherEntities(UnityMover m)
    {
        Vector2 vec = Vector2.zero;
        float   dst = 10;

        foreach (UnityEntity e in m.unityEntities)
        {
            if (m != e && e.gameObject.activeSelf)
            {
                if (Utility.Intersectcs(m.entity.rect, e.entity.rect))
                {
                    Vector2 newVec = m.entity.position - e.entity.position;

                    float newDst = newVec.magnitude;

                    if (newDst < dst)
                    {
                        vec = newVec;
                        dst = newDst;
                    }

                    float minAngle = Utility.MinDropAngle(m.entity.rect, e.entity.rect);

                    minAngle = 90 - minAngle;

                    float angle = Vector2.Angle(vec, Vector2.up);

                    if (angle < minAngle + 5)
                    {
                        m.HitTop(e);
                    }
                    else if (angle >= minAngle - 5 && angle <= 180 - minAngle)
                    {
                        m.HitSide(e, vec.x);
                    }
                    else
                    {
                        m.HitBottom(e);
                    }
                }
            }
        }
    }