Exemplo n.º 1
0
    void RayCastCheck()
    {
        if (Input.GetMouseButtonDown(1))
        {
            lineOrigin = mousePoint;
        }

        Vector3 dirction = mousePoint - lineOrigin;

        ShapeObject[] shapes = ShapeQuadTree.OverlapLine(lineOrigin, dirction);

        foreach (var shape in shapes)
        {
            shape.SetColor(Color.black * 0.8f);
        }

        shapes = ShapesCollision.RayCast(lineOrigin, dirction);
        foreach (var shape in shapes)
        {
            shape.SetColor(Color.white * 0.8f);
        }
        text.text = shapes.Length.ToString();
        text.transform.position = lineOrigin;
    }
Exemplo n.º 2
0
        //Raycast Check
        public static ShapeObject[] RayCast(Vector3 origin, Vector3 dirction)
        {
            dirction = dirction.normalized;

            ShapeObject[]      checking       = ShapeQuadTree.OverlapLine(origin, dirction);
            List <ShapeObject> IsCastHitShape = new List <ShapeObject>();

            if (DrawOverlap)
            {
                Debug.DrawRay(origin, dirction * 50);
            }

            for (int i = 0; i < checking.Length; i++)
            {
                ShapeObject checkedShape  = checking[i];
                Vector3     rayProjection = Vector2.Perpendicular(dirction);
                if (ShapeDirctionOfRayCast(checkedShape, origin, dirction) && ShapeProjectionOverlapWithPoint(checkedShape, origin, rayProjection).HasCollision)
                {
                    IsCastHitShape.Add(checkedShape);
                }
            }

            return(IsCastHitShape.ToArray());
        }