Пример #1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.name.Contains("Terrain"))
        {
            Vector2f pos = new Vector2f(transform.position);

            Polygon.defaultCircleVerticesCount = 15;;
            Polygon slicePolygon = Polygon.Create(Polygon.PolygonType.Circle, 2f);

            Polygon slicePolygonDestroy = null;
            Polygon sliceDestroy        = null;

            slicePolygonDestroy = Polygon.Create(Polygon.PolygonType.Circle, 2.5f);
            sliceDestroy        = new Polygon();

            foreach (Vector2f id in slicePolygonDestroy.pointsList)
            {
                sliceDestroy.AddPoint(new Vector2f(id.Get() + pos.Get()));
            }

            Polygon slice = new Polygon();
            foreach (Vector2f id in slicePolygon.pointsList)
            {
                slice.AddPoint(new Vector2f(id.Get() + pos.Get()));
            }

            foreach (Slicer2D id in Slicer2D.GetList())
            {
                Slice2D result = id.PolygonSlice2(slice);                  // Why not use Slice All?
                if (result.polygons.Count > 0)
                {
                    foreach (Polygon p in new List <Polygon>(result.polygons))
                    {
                        if (sliceDestroy.PolyInPoly(p) == true)
                        {
                            result.polygons.Remove(p);
                        }
                    }

                    if (result.polygons.Count > 0)
                    {
                        id.PerformResult(result.polygons);
                    }
                    else
                    {
                        Destroy(id.gameObject);
                    }
                }
            }
            Destroy(gameObject);

            Polygon.defaultCircleVerticesCount = 25;
        }
    }
Пример #2
0
    void Start()
    {
        Vector2f position = new Vector2f(anchorBody.transform.position);

        GameObject prev = anchorBody;

        int        ropeId  = 1;
        GameObject gObject = null;

        while (Vector2f.Distance(position, new Vector2f(connectedBody.transform.position)) > .5f)
        {
            float direction = Vector2f.Atan2(new Vector2f(connectedBody.transform.position), position);

            gObject = new GameObject();
            gObject.AddComponent <HingeJoint2D>().connectedBody = prev.GetComponent <Rigidbody2D>();

            gObject.transform.parent   = transform;
            gObject.transform.position = position.Get();
            gObject.name = "Rope " + ropeId;
            gObject.AddComponent <JointRenderer2D> ().color   = color;
            gObject.AddComponent <CircleCollider2D> ().radius = .25f;

            nodes.Add(gObject);

            position.Push(direction, .5f);

            prev = gObject;
            ropeId++;
        }

        if (gameObject != null)
        {
            gObject.AddComponent <HingeJoint2D>().connectedBody = connectedBody.GetComponent <Rigidbody2D>();
        }
    }
Пример #3
0
 /// <summary>
 /// Distance between given 2D vectors
 /// </summary>
 public static float Distance(Vector2f a, Vector2f b)
 {
     return(Vector2.Distance(a.Get(), b.Get()));
 }