예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        Vector3 a = new Vector3(3, 4, 8);
        Vector3 b = new Vector3(3, 4, 8);

        Vector3 c = Vet.Soma(a, b);

        print(c);
        print(Vet.MultiplicarEscalar(c, 3.0f));
        print(Vet.Magnitude(c));
        print(Vet.Normalizar(c));
        print(Vet.Magnitude(Vet.Normalizar(c)));
    }
예제 #2
0
    private void FixedUpdate( )
    {
        e = MouseController.controller.qualExercicio;

        if (e == 1)
        {
            chao.SetActive(false);

            if (deslocamentoAngular > 1.0f)
            {
                passoAngular         = distanciaAngular * Time.deltaTime / tempoRotacao;
                transform.rotation   = Quaternion.Euler(Vet.Soma(transform.rotation.eulerAngles, new Vector3(0, 0, passoAngular)));
                deslocamentoAngular -= Mathf.Abs(passoAngular);
            }
            else if (Vet.Magnitude(deslocamentoLinear) > 1.0f)
            {
                passoLinear        = distanciaLinear * Time.deltaTime / tempoTranslacao;
                transform.position = Vet.Soma(transform.position, passoLinear);
                deslocamentoLinear = Vet.Subtrai(deslocamentoLinear, passoLinear);
            }
        }
        else if (e == 2)
        {
            chao.SetActive(false);

            if (direcao != null)
            {
                Vector3 diferencaAngular = Vet.Subtrai(direcao, transform.position);
                float   anguloNovo       = Mathf.Atan2(diferencaAngular.y, diferencaAngular.x) * Mathf.Rad2Deg + 90;
                transform.rotation = Quaternion.Euler(new Vector3(0, 0, anguloNovo));

                if (!jato.isStopped)
                {
                    // ALTERANDO A QUANTIDADE DE MOVIMENTO / MOMENTO LINEAR
                    // MASSA É CONSTANTE, PORTANTO, O QUE VARIA É A VELOCIDADE
                    float impulso = forcaJato * Time.fixedDeltaTime;
                    // IMPULSO É IGUAL À VARIAÇÃO DA QUANTIDADE DE MOVIMENTO
                    float deltaQ  = impulso;
                    float deltaV  = deltaQ / massaNave;
                    float deltaVx = deltaV * Mathf.Cos((transform.root.eulerAngles.z - 90) * Mathf.Deg2Rad);
                    float deltaVy = deltaV * Mathf.Sin((transform.root.eulerAngles.z - 90) * Mathf.Deg2Rad);
                    Vx += deltaVx;
                    Vy += deltaVy;
                }

                Vector3 tp = transform.position;
                transform.position = new Vector3(
                    tp.x + Vx * Time.fixedDeltaTime,
                    tp.y + Vy * Time.fixedDeltaTime,
                    zFixo
                    );
            }
        }
        else if (e == 3)
        {
            chao.SetActive(true);

            if (direcao != null)
            {
                Vector3 diferencaAngular = Vet.Subtrai(direcao, transform.position);
                float   anguloNovo       = Mathf.Atan2(diferencaAngular.y, diferencaAngular.x) * Mathf.Rad2Deg + 90;
                transform.rotation = Quaternion.Euler(new Vector3(0, 0, anguloNovo));

                float forcaX = 0;
                float forcaY = gravidade;

                if (!jato.isStopped)
                {
                    // AGORA SEPARANDO JÁ NO IMPULSO OS VALORES EM X E Y
                    // POR QUE GRAVIDADE SÓ VAI AFETAR EM Y
                    forcaX += forcaJato * Mathf.Cos((transform.root.eulerAngles.z - 90) * Mathf.Deg2Rad);
                    forcaY += forcaJato * Mathf.Sin((transform.root.eulerAngles.z - 90) * Mathf.Deg2Rad);
                }

                float Ax = forcaX / massaNave;
                float Ay = forcaY / massaNave;

                Vx = Vx + Ax * Time.fixedDeltaTime;
                Vy = Vy + Ay * Time.fixedDeltaTime;

                Vector3 tp = transform.position;
                transform.position = new Vector3(
                    tp.x + Vx * Time.fixedDeltaTime,
                    tp.y + Vy * Time.fixedDeltaTime,
                    zFixo
                    );

                if (transform.position.y < -4.2)
                {
                    Vy *= -1;
                }
            }
        }
    }