Exemplo n.º 1
0
        public IEnumerable <RaycastHit2D> CheckStaticCollisions(LayerMask layer, Vector2 pos)
        {
            Func <Vector2, RaycastHit2D> rayCast = (component) => {
                Vector2 vertical  = new Vector2(-component.y, component.x); // -90degree
                Vector2 originPos = pos + VectorUtils.Multiply(size, component) / 2 + VectorUtils.Multiply(vertical, size) / 2 - vertical * skinWidth;
                float   length    = VectorUtils.Multiply(vertical, size).magnitude - 2 * skinWidth;
                return(Physics2D.Raycast(originPos, -vertical, length, layer));
            };

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if ((i == 0 && j != 0) || (i != 0 && j == 0))
                    {
                        var hit = rayCast(new Vector2(i, j));
                        if (hit)
                        {
                            yield return(hit);
                        }
                    }
                }
            }
            yield break;
        }
Exemplo n.º 2
0
 private Vector2 v32(Vector3 v3)
 {
     return(VectorUtils.V32(v3));
 }
Exemplo n.º 3
0
        public void BlockMoving(Vector2 mov)
        {
            Action <Vector2> process = (component) => {//up or right
                Vector2 vertical = new Vector2(1 - component.x, 1 - component.y);
                float?  minHit   = blockBoxCollision.CheckMoveCollision(VectorUtils.Multiply(mov, component), blockLayer);
                if (minHit == null)
                {
                    return;
                }
                mov = VectorUtils.Multiply(mov, vertical) + minHit.Value * component * VectorUtils.Do(mov, Mathf.Sign);
            };

            process(Vector2.right);
            position += mov.x * Vector2.right;
            process(Vector2.up);
            position += mov.y * Vector2.up;
        }