Beispiel #1
0
 public VerticeGroup(int vertID, float xAxis, float zAxis, PhysicsBall pb)
 {
     x           = xAxis;
     z           = zAxis;
     physicsBall = pb;
     verticesIDs = new List <int>();
     verticesIDs.Add(vertID);
     isCenter = false;
 }
 public void SetBalls(PhysicsBall ballA, PhysicsBall ballB)
 {
     if (IsLeft(ballA.transform.position))
     {
         leftBall  = ballA;
         rightBall = ballB;
     }
     else
     {
         leftBall  = ballB;
         rightBall = ballA;
     }
 }
Beispiel #3
0
    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.layer == LayerMask.NameToLayer("PhysicsBall") && selfPolygonCollider2D.enabled == true)
        {
            if (basketState == 0)
            {
                PhysicsBall tempPhysicsBall = col.transform.GetComponent <PhysicsBall>();
                if (this.colorIndex == tempPhysicsBall.colorIndex)
                {
                    basketState = 1;
                }
                else
                {
                    basketState = -1;
                }
            }
            else
            {
                basketState = -2;
            }
        }

        LevelController.instance.GameStateRefresh();
    }
Beispiel #4
0
    // Some form of physic ball, i still need to work it out :)

    void Awake()
    {
        // get the mesh and all of the verts
        mesh       = GetComponent <MeshFilter>().mesh;
        vertices   = mesh.vertices;
        vertGroups = new List <VerticeGroup>();

        // loop all verts and group them into x, z group.
        for (int i = 0; i < vertices.Length; i++)
        {
            int vertGroupId = FindExistingVertGroup(vertices[i].x, vertices[i].z);

            if (vertGroupId > -1)               // add to existing group
            {
                vertGroups[vertGroupId].AddVertID(i);
            }
            else             // Creat new group
            {
                PhysicsBall tempBall = Instantiate(physicsBall, transform);
                vertGroups.Add(new VerticeGroup(i, vertices[i].x, vertices[i].z, tempBall));                            //TODO: change null to physic ball :)

                tempBall.transform.localPosition = vertGroups[vertGroups.Count - 1].GetAsVector3();
                tempBall.name = "TB_" + i;

                if (centerId == -1 && vertices[i].x == 0 && vertices[i].z == 0)
                {
                    centerId = vertGroups.Count - 1;
                    vertGroups[centerId].SetCenter(true);
                }
            }
        }

        // so now we have all the verts into groups, we need to find wich groups are to the left and right of the current.

        float distanceFromCenter = 0;

        for (int i = 0; i < vertGroups.Count; i++)
        {
            //Skip the center Id, since id does not need a left and right
            if (i == centerId)
            {
                continue;
            }
            // creat two list for the two cloest points that are distance from center.
            List <int>   cloestId = new List <int>(2);
            List <float> dist     = new List <float>(2);

            cloestId.AddRange(new int[2] {
                0, 0
            });
            dist.AddRange(new float[2] {
                100f, 100f
            });

            distanceFromCenter = Vector3.Distance(Vector3.zero, vertGroups[i].GetAsVector3());

            for (int j = 0; j < vertGroups.Count; j++)
            {
                // skip cemter and itself
                if (j == centerId || j == i)
                {
                    continue;
                }

                // we only need the left and right that are on the same ring as the current vert.
                // NOTE TO ME.
                // Keep an eye on this, since it's outside of the current testing scope.
                // reseon being is that "Vector3.Distance( Vector3.zero, vertGroups[ j ].GetAsVector3() ) != distanceFromCenter" was no evelateing correctly
                // some times it would evelate as TRUE when both where the same. Im going to put it down to rounding error :(
                // But still this should be the first point of contact if there are any issues like this in a more rigarus test.
                if (!Mathf.Approximately(Vector3.Distance(Vector3.zero, vertGroups[j].GetAsVector3()), distanceFromCenter))
                {
                    continue;
                }

                // find if its cloestes
                float tempDistance = Vector3.Distance(vertGroups[i].GetAsVector3(), vertGroups[j].GetAsVector3());

                for (int cid = 0; cid < cloestId.Count; cid++)
                {
                    if (j == cid || tempDistance < dist[cid])
                    {
                        cloestId.Insert(cid, j);
                        dist.Insert(cid, tempDistance);
                        break;
                    }
                }
            }

            // set it up on a Physic ball
            // TODO: ^^^
            vertGroups[i].physicsBall.SetBalls(vertGroups[cloestId[0]].physicsBall, vertGroups[cloestId[1]].physicsBall);
        }
    }