Exemplo n.º 1
0
    public void setHero2D(bool b)
    {
        if (b)
        {
            if (facingRight)
            {
                Hero2D.SetActive(true);
            }
            else
            {
                Hero2DInverse.SetActive(true);
            }

            HeroTiltedRight.SetActive(false);
            HeroTiltedLeft.SetActive(false);
            HeroTiltedRightBackwards.SetActive(false);
            HeroTiltedLeftBackwards.SetActive(false);

            InvertedDragonTiltedLeft.SetActive(false);
            InvertedDragonTiltedRight.SetActive(false);
            InvertedDragonTiltedLeftBackwards.SetActive(false);
            InvertedDragonTiltedRightBackwards.SetActive(false);
        }
        else
        {
            GameObject.FindGameObjectWithTag("Player").transform.position = original3DPosition;

            Hero2D.SetActive(false);
            Hero2DInverse.SetActive(false);
            if (facingRight)
            {
                setHeroDirection(0);
            }
            else
            {
                setHeroDirection(2);
            }
        }
    }
Exemplo n.º 2
0
    void UpdateMovement()
    {
        // Movement
        float z = -Input.GetAxis("Horizontal");
        float x = Input.GetAxis("Vertical");

        checkRunningAnimation(z, x);

        Vector3 inputVec;

        //	timeAtStartOfMovement = Time.time;
        // Se esta nas escadas trata o input de outra forma
        if (touchingLadder && x == 1)
        {
            if (!charOnLadder && x == 1)                                       // Se ainda nao estiver a subir e pressionar "Up"
            {
                charOnLadder = true;
            }
            else                                         // Se ja estiver a subir
            {
                inputVec = new Vector3(0, 0, 0);
                Debug.Log("Touching Ladder");
                if (x == 1)                                                   // Going up
                {
                    lastLadderMovementUp = true;
                    if (!canJump && controller.isGrounded)                                                               // Encontra-se no topo
                    {
                        controller.Move((new Vector3(0f, 5f, 50f) + Vector3.up * -gravity + new Vector3(0, verticalVel, 0)) * Time.deltaTime);
                    }
                    else                                                                 // Encontra-se a meio da escada
                    {
                        canJump = false;
                        //	verticalVel += runSpeed;
                        //	controller.Move ((inputVec + Vector3.up * -gravity + new Vector3 (0, verticalVel, 0)) * Time.deltaTime);
                        controller.Move(new Vector3(0f, 0.09f, 0f));
                    }
                }
                else if (x == -1)                                                     // Going down
                {
                    lastLadderMovementUp = false;
                    if (!controller.isGrounded)
                    {
                        canJump = false;
                        //	verticalVel -= runSpeed;
                        //	controller.Move ((inputVec + Vector3.up * -gravity + new Vector3 (0, verticalVel, 0)) * Time.deltaTime);
                        controller.Move(new Vector3(0f, -0.09f, 0f));
                    }
                    else                                                                 // Already on Floor
                    {
                        canJump        = true;
                        touchingLadder = false;
                        charOnLadder   = false;
                        Debug.Log("IS GROUNDED");
                    }
                }
            }
        }
        else
        {
            // Movimento 3D
            if (GameObject.FindGameObjectWithTag("Player").GetComponent <GameLogic> ().Camera3D.enabled)
            {
                // Verifica se a posiçao e invertida
                if (GameObject.FindGameObjectWithTag("Player").
                    GetComponent <GameLogic> ().Camera3D.GetComponent <PlayerTracker> ().dir == -1)
                {
                    x *= -1;
                    z *= -1;
                }

                inputVec = new Vector3(x, 0, z) * runSpeed * 2;

                // Check Ladder
                {                                                 // Movimento normal
                    controller.Move((inputVec + Vector3.up * -gravity + new Vector3(0, verticalVel, 0)) * Time.deltaTime);

                    if (z == -1 && !tiltedtoCamIn3D)
                    {
                        if (facingBackwards)
                        {
                            setHeroDirection(2);
                        }
                        else
                        {
                            setHeroDirection(0);
                        }
                        //	GameObject.FindGameObjectWithTag ("Hero_Inverse").GetComponent
                        //		GameObject.FindGameObjectWithTag ("Hero").SetActive(true);
                    }
                    else if (z == 1 && tiltedtoCamIn3D)
                    {
                        if (facingBackwards)
                        {
                            setHeroDirection(3);
                        }
                        else
                        {
                            setHeroDirection(1);
                        }
                    }

                    if (x == -1 && !facingBackwards)
                    {
                        if (tiltedtoCamIn3D)
                        {
                            setHeroDirection(2);
                        }
                        else
                        {
                            setHeroDirection(3);
                        }
                    }
                    else if (x == 1 && facingBackwards)
                    {
                        if (tiltedtoCamIn3D)
                        {
                            setHeroDirection(0);
                        }
                        else
                        {
                            setHeroDirection(1);
                        }
                    }
                }
            }
            else                                         // Movimento 2D
            {
                if (z == -1)
                {
                    facingRight = true;
                    Hero2DInverse.SetActive(false);
                    Hero2D.SetActive(true);
                }
                else if (z == 1)
                {
                    facingRight = false;
                    Hero2DInverse.SetActive(true);
                    Hero2D.SetActive(false);
                }
                inputVec = new Vector3(-z, 0, 0) * runSpeed * 2;
                controller.Move((inputVec + Vector3.up * -gravity + new Vector3(0, verticalVel, 0)) * Time.deltaTime);
            }
        }
    }
Exemplo n.º 3
0
    /**
     * @params: dir
     *  0 = tilted right (or left in inverse)
     *  1 = tilted left
     *  2 = tilted right (from camera perspective) backwards
     *  3 = tilted left (from camera perspective) backwards
     **/
    public void setHeroDirection(int dir)
    {
        Hero2D.SetActive(false);
        Hero2DInverse.SetActive(false);

        if (GameObject.FindGameObjectWithTag("Player").
            GetComponent <GameLogic> ().Camera3D.GetComponent <PlayerTracker> ().dir == 1)
        {
            if (dir == 0)
            {
                tiltedtoCamIn3D = true;
                facingBackwards = false;
                HeroTiltedRight.SetActive(true);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 1)
            {
                tiltedtoCamIn3D = false;
                facingBackwards = false;
                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(true);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 2)
            {
                facingBackwards = true;
                tiltedtoCamIn3D = true;
                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(true);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 3)
            {
                facingBackwards = true;
                tiltedtoCamIn3D = false;
                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(true);
            }
        }
        else if (GameObject.FindGameObjectWithTag("Player").
                 GetComponent <GameLogic> ().Camera3D.GetComponent <PlayerTracker> ().dir == -1)
        {
            if (dir == 0)
            {
                tiltedtoCamIn3D = true;
                facingBackwards = false;

                InvertedDragonTiltedLeft.SetActive(false);
                InvertedDragonTiltedRight.SetActive(false);
                InvertedDragonTiltedLeftBackwards.SetActive(true);
                InvertedDragonTiltedRightBackwards.SetActive(false);

                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 1)
            {
                tiltedtoCamIn3D = false;
                facingBackwards = false;

                InvertedDragonTiltedLeft.SetActive(false);
                InvertedDragonTiltedRight.SetActive(false);
                InvertedDragonTiltedLeftBackwards.SetActive(false);
                InvertedDragonTiltedRightBackwards.SetActive(true);

                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 2)
            {
                facingBackwards = true;
                tiltedtoCamIn3D = true;

                InvertedDragonTiltedLeft.SetActive(true);
                InvertedDragonTiltedRight.SetActive(false);
                InvertedDragonTiltedLeftBackwards.SetActive(false);
                InvertedDragonTiltedRightBackwards.SetActive(false);

                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
            else if (dir == 3)
            {
                facingBackwards = true;
                tiltedtoCamIn3D = false;

                InvertedDragonTiltedLeft.SetActive(false);
                InvertedDragonTiltedRight.SetActive(true);
                InvertedDragonTiltedLeftBackwards.SetActive(false);
                InvertedDragonTiltedRightBackwards.SetActive(false);

                HeroTiltedRight.SetActive(false);
                HeroTiltedLeft.SetActive(false);
                HeroTiltedRightBackwards.SetActive(false);
                HeroTiltedLeftBackwards.SetActive(false);
            }
        }
    }