Exemplo n.º 1
0
    void Start()
    {
        GameObject gi = GameObject.Find("GameInitializer");

        props = (Properties)gi.transform.GetComponent("Properties");

        sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        sphere.transform.localScale = new Vector3(2 * radius, 2 * radius, 2 * radius);
        SphereCollider col = sphere.GetComponent <SphereCollider> ();

        col.isTrigger = true;
        sphere.AddComponent <WallHit> ();
        sphere.AddComponent <Rigidbody> ();
        sphere.transform.parent = transform;
        alivetime = 2.0f;

        mountain    = (CreateMountain)gi.transform.GetComponent("CreateMountain");
        trycounter  = 0;
        goatspawner = GameObject.Find("GoatSpawner");
    }
Exemplo n.º 2
0
    // called multiple times per frame
    public bool SolveConstraints()
    {
        // Stretch or pull all points from links
        for (int i = 0; i < links.Count; i++)
        {
            PointLink currlink = (PointLink)links [i];
            currlink.Solve();
        }

        // Skip most if point is anchored (cannot change)
        if (!anchored)
        {
            // Boundary Constraints, true return deletes the goat
            if (position.y < -4f)
            {
                return(true);
            }
            if (position.y > 11f)
            {
                return(true);
            }
            if (position.x > 11f)
            {
                return(true);
            }
            if (position.x < -11f)
            {
                return(true);
            }

            // Constraints to hit mountain
            CreateMountain   mountain = (CreateMountain)gi.GetComponent("CreateMountain");
            TriangleStruct[] left     = mountain.lefttriangles;
            TriangleStruct[] right    = mountain.righttriangles;
            TriangleStruct   top      = mountain.toptriangle;

            if (position.y <= 2.0f)
            {
                // left
                if (position.x >= -5.0f && position.x <= -1.0f)
                {
                    for (int i = 0; i < left.Length; i++)
                    {
                        TriangleStruct lefttri = (TriangleStruct)left [i];
                        if (lefttri.PointInTriangle(position))
                        {
                            position = lefttri.Relocate(position);
                            if (isAnchor)
                            {
                                anchored = true;
                                anchor   = position;
                            }
                        }
                    }
                }
                // right
                else if (position.x >= 1.0f && position.x <= 5.0f)
                {
                    for (int i = 0; i < right.Length; i++)
                    {
                        TriangleStruct righttri = (TriangleStruct)right [i];
                        if (righttri.PointInTriangle(position))
                        {
                            position = righttri.Relocate(position);
                            if (isAnchor)
                            {
                                anchored = true;
                                anchor   = position;
                            }
                        }
                    }
                }
                // middle
                else if (position.x >= -1.0f && position.x <= 1.0f)
                {
                    if (top.PointInTriangle(position))
                    {
                        position = top.Relocate(position);
                        if (isAnchor)
                        {
                            anchored = true;
                            anchor   = position;
                        }
                    }
                }
            }
        }
        // pin to mountain if anchored by a foot
        if (anchored)
        {
            position = anchor;
        }
        return(false);
    }