Ejemplo n.º 1
0
 // Start is called before the first frame update
 void Start()
 {
     if (myMove == null && GetComponent <AI_Move>() != null)
     {
         myMove = GetComponent <AI_Move>();
     }
 }
Ejemplo n.º 2
0
 /**
  * @desc - This method gets called just before any of the Update methods is called
  */
 private void Start()
 {
     SetLobbyUI(true); //is in lobby
     player2MovementController = player2.GetComponent <MovementController>();
     player2AIController       = player2.GetComponent <AI_Move>();
     player1.SetActive(false);
     player2.SetActive(false);
 }
Ejemplo n.º 3
0
    //---------------------------------------------------------------------
    // Update is called once per frame, Used to check for the closest
    // object to the AI depending on which data structure is picked.
    //---------------------------------------------------------------------
    void Update()
    {
        if (m_bKdTree)
        {
            // Updates the AI agents that were added at the start
            m_BlackAgents.UpdatePositions();

            foreach (var m_WhiteAgent in m_WhiteAgents)
            {
                // Finds the closest AI
                AI_Move nearestObject = m_BlackAgents.FindClosest(m_WhiteAgent.transform.position);
                // Draws a debug line between them.
                Debug.DrawLine(m_WhiteAgent.transform.position, nearestObject.transform.position, Color.red);
            }
        }
        else if (m_bQuadTree)
        {
            GameObject whiteAgent;
            foreach (var m_WhiteAgent in m_WhiteAgents)
            {
                // Inserts the AI into the quad tree
                newObject = new TestObject(m_WhiteAgent.transform.position);
                quadTree.Insert(newObject);
                // Resets the shortest distance
                shortestDistance = Mathf.Infinity;
                // Sets the rect area to retrieve the objects
                m_rect = new Rect(newObject.GetPosition(), recSize);
                // retrieves all objects in the area
                m_QuadAgentsWhite = quadTree.RetrieveObjectsInArea(m_rect);

                // Gets the shortest distance between the AI
                for (int i = 0; i < m_QuadAgentsWhite.Count; i++)
                {
                    var distance = Vector3.Distance(m_WhiteAgent.transform.position, m_QuadAgentsWhite[i].GetPosition());
                    if (distance < shortestDistance)
                    {
                        shortestDistance = distance;
                        whiteAgent       = m_WhiteAgent.gameObject;
                    }
                }
            }
        }
        else if (!m_bKdTree && !m_bQuadTree)
        {
            foreach (var m_WhiteAgent in m_WhiteAgents)
            {
                // Variables used to calculate the closest AI
                var     nearestDist = float.MaxValue;
                AI_Move nearestObj  = null;
                shortestDistance = Mathf.Infinity;

                foreach (var m_BlackAgent in m_BlackAgents)
                {
                    // Gets the shortest distance between the AI
                    nearestDist = Vector3.Distance(m_WhiteAgent.transform.position, m_BlackAgent.transform.position);

                    if (nearestDist < shortestDistance)
                    {
                        shortestDistance = nearestDist;
                        // Sets the closest AI
                        nearestObj = m_BlackAgent;
                    }
                }
                // Draws a debug line between the closest AI
                Debug.DrawLine(m_WhiteAgent.transform.position, nearestObj.transform.position, Color.red);
            }
        }
    }
    //public float jumpSpeed = 10f;


    // Use this for initialization
    void Start()
    {
        triggerSwitch = GameObject.Find("boat1").GetComponent <AI_Move> ();

        //scanPt = GameObject.Find ("sqaure").transform;
    }