Ejemplo n.º 1
0
    /*private void OnTriggerExit(Collider other)
     * {
     *  if (other.CompareTag("Potion"))
     *  {
     *      Debug.Log("Reativando colisão");
     *      other.enabled = true;
     *  }
     * }*/


    //O: Função que altera o valor da variável canThrow caso o jogador esteja ou não congelado
    private bool GetCanThrow()
    {
        bool freeze = playerEffects.HasEffect(PotionEffect.Freeze);

        if (freeze)
        {
            canThrow = false;
        }
        else
        {
            canThrow = true;
        }
        return(canThrow);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale == 0.0f)
        {
            return;
        }
        bool  inv      = plEffects.HasEffect(PotionEffect.Invert); //O: Verifica se o jogador foi atingido pelo orbe de confusão
        float adjSpeed = GetAdjustedSpeed();                       //K: a velocidade de movimento que deve ser usada, considerando os efeitos que podem afetá-la

        //Movimenta jogador
        //mudei as funções de Input.GetAxisRaw para InputManager.GetAxis, usando a classe que fiz para lidar com controles. Ass: Krauss
        float moveHon = InputManager.GetAxis(playerInput.controllerScheme, "HorizontalL");
        float moveVer = InputManager.GetAxis(playerInput.controllerScheme, "VerticalL");
        //Debug.Log(moveVer);
        Vector3 newMove = new Vector3(moveHon, 0.0f, moveVer);


        //calcula qual deve ser a velocidade do player
        if (newMove.sqrMagnitude > 0.1f)
        {
            //O: Inverte a direção do movimento do jogador ao ser atingido pelo orbe de confusão
            //K: use as chavinhas {} pra marcar os ifs, por favor eu imploro
            if (inv)
            {
                move = -1 * newMove;
            }
            else
            {
                //se player está inserindo input, ele tenta acelerar, até o limite da velocidade máxima
                move = newMove;
            }
            currentSpeed = Mathf.SmoothDamp(currentSpeed, adjSpeed, ref yAcceleration, accelerationTime);
        }
        else
        {
            //senão, desacelera
            //V = V0 + at => Vframe = V(ultimoframe) + baseDeceleration * Time.deltaTime
            //repare que baseDeceleration já é negativo!
            currentSpeed = Mathf.Max(0.0f, currentSpeed + baseDeceleration * Time.deltaTime);
        }


        //move o player
        //transform.position += move.normalized * Time.deltaTime * currentSpeed;
        rigidbody.velocity = move * currentSpeed;

        foreach (Animator anim in animator)
        {
            anim.SetBool("Walking", currentSpeed > 0);
        }


        //Calcula direção
        //angle = Mathf.Atan2(moveVer, moveHon);
        //angle = Mathf.Rad2Deg * angle;

        //angle += cam.eulerAngles.y; //não entendi o que exatamente a camera tem a ver com essa rotação. Esse valor é 0 de qquer forma Ass: Krauss

        //Rotaciona o jogador
        //rot = Quaternion.Euler(0, angle, 0);

        //se o player está usando um controle para jogar,
        if (playerInput.controllerScheme.mode == ControllerMode.Joystick)
        {
            float   h     = InputManager.GetAxis(playerInput.controllerScheme, "HorizontalR");
            float   v     = InputManager.GetAxis(playerInput.controllerScheme, "VerticalR");
            Vector2 input = new Vector2(h, v);


            //se o player está usando o analógico direito para se rotacionar, imediatamente vai para aquela orientação(por ora pelo menos)
            if (ManualRotate && input.magnitude >= 0.6f) //botei um thrshold de 0.6 pra ele não ficar rodando a esmo e ficar sempre na direção do último input
            {
                float      angle_rad = Mathf.Atan2(input.x, input.y);
                Quaternion rotation  = new Quaternion();
                rotation.eulerAngles = new Vector3(0.0f, angle_rad * Mathf.Rad2Deg, 0.0f);
                transform.rotation   = rotation;
            }
            else if (AutoRotate && move.magnitude > 0)
            {
                //auto-rotaciona
                rot = Quaternion.LookRotation(move, Vector3.up);
                //rotaciona jogador
                transform.rotation = Quaternion.Lerp(transform.rotation, rot, turnSpeed);
            }
        }
        else if (move.magnitude > 0)
        {
            //se o player está controlando no teclado, a única maneira de rotacionar é autorotacionando.

            //calcula rotação
            rot = Quaternion.LookRotation(move, Vector3.up);
            //rotaciona jogador
            transform.rotation = Quaternion.Lerp(transform.rotation, rot, turnSpeed);
        }
    }