Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (m_Path == null)
        {
            return;
        }

        float distToPlayer = Vector3.Distance(transform.position, m_PlayerPos.position);

        if (m_CurrentWayPoint >= m_Path.vectorPath.Count)
        {
            // requeue if not in attack range
            if (m_Comb != null)
            {
                if (distToPlayer > m_Comb.GetAttackRange())
                {
                    FindNewPath();
                }
            }
            return;
        }

        //update path every 30 frames
        if (Time.frameCount % 30 == 0)
        {
            FindNewPath();
        }


        Vector3 moveDir = (m_Path.vectorPath[m_CurrentWayPoint] - transform.position).normalized;

        moveDir *= m_MoveSpeed;

        m_CharController.SimpleMove(moveDir);

        if (Vector3.Distance(transform.position, m_Path.vectorPath[m_CurrentWayPoint]) <= m_NextWayPointDist)
        {
            m_CurrentWayPoint++;
        }

        //also check for range
        if (m_Comb != null)
        {
            if (distToPlayer < m_Comb.GetAttackRange())
            {
                //destination reached
                m_CurrentWayPoint = m_Path.vectorPath.Count;
            }
        }
    }