Exemplo n.º 1
0
        //find the closest ball to a pocket.
        public override void findBallAndPocket()
        {
            float         d0 = 1000000f;
            PocketTrigger pt = null;

            for (int i = 0; i < m_balls.Length; i++)
            {
                bool useBall = canUseBall(m_balls[i]);


                if (m_balls[i] &&
                    m_balls[i].pocketed == false &&
                    m_balls[i] != m_whiteBall &&
                    useBall)
                {
                    //m_targetPos = findClosestPocketToBall(m_targetBall,ref d0);

                    for (int j = 0; j < m_pockets.Length; j++)
                    {
                        float d1 = (m_pockets[j].getPosition() - m_balls[i].transform.position).magnitude;

                        if (d1 < d0)
                        {
                            m_targetBall = m_balls[i];
                            pt           = m_pockets[j];
                            m_targetPos  = m_pockets[j].getPosition();
                            d0           = d1;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void findClosestAngleToBall()
        {
            float         d0 = 1000000f;
            PocketTrigger pt = null;

            for (int j = 0; j < m_pockets.Length; j++)
            {
                if (m_targetBall)
                {
                    Vector3 targetDir = m_pockets[j].transform.position - m_targetBall.transform.position;                   // - m_pockets[j].transform.position;
                    Vector3 forward   = m_targetBall.transform.position - m_whiteBall.transform.position;
                    float   D1        = Vector3.Angle(targetDir, forward);

                    if (D1 < d0)
                    {
                        pt          = m_pockets[j];
                        m_targetPos = m_pockets[j].transform.position;
                        d0          = D1;
                    }
                }
            }
            if (pt)
            {
//				Debug.Log ("Pocket Trigger " + pt.name);
            }
        }