コード例 #1
0
    /// <summary>
    /// Função que o veículo segue o alvo.
    /// </summary>
    void Chasing()
    {
        Vector3 targetPosition = Singletons.GetPlayer().transform.position;
        Vector3 actualPosition = m_transform.position;

        //Checando a direção do alvo.
        Vector3 targetDirection = (targetPosition - actualPosition).normalized;

        //Checando se o alvo está à frente. Se estiver a frente, irá seguir reto.
        if (Vector3.Dot(m_transform.forward, targetDirection) < 0.9)
        {
            //Checando se o alvo está mais a direita ou esquerda.
            if (Vector3.Dot(m_transform.right, targetDirection) > 0)
            {
                Turn(1f);
            }
            else
            {
                Turn(-1f);
            }
        }
        else
        {
            Turn(0f);
        }

        //Acelera o veículo.
        Acellerate(1f);
    }