예제 #1
0
 public void OnJumpInputDown()
 {
     if (Time.timeScale > 0)
     {
         if (wallSliding)
         {
             AudioManager.Instance.PlayJumpSound();
             playerAnimationController.Jump();
             if (wallDirX == directionalInput.x)
             {
                 velocity.x = -wallDirX * wallJumpClimb.x;
                 velocity.y = wallJumpClimb.y;
             }
             else if (directionalInput.x == 0)
             {
                 velocity.x = -wallDirX * wallJumpOff.x;
                 velocity.y = wallJumpOff.y;
             }
             else
             {
                 velocity.x = -wallDirX * wallLeap.x;
                 velocity.y = wallLeap.y;
             }
         }
         if (controller.collisions.below || timeSinceLastBelow < 0.12f)
         {
             timeSinceLastBelow = 1;
             AudioManager.Instance.PlayJumpSound();
             playerAnimationController.Jump();
             if (controller.collisions.slidingDownMaxSlope)
             {
                 if (directionalInput.x != -Mathf.Sign(controller.collisions.slopeNormal.x))                       // not jumping against max slope
                 {
                     velocity.y = MaxJumpVelocity * controller.collisions.slopeNormal.y;
                     velocity.x = MaxJumpVelocity * controller.collisions.slopeNormal.x;
                 }
             }
             else
             {
                 velocity.y = MaxJumpVelocity;
             }
         }
     }
 }
예제 #2
0
    private void PlayAnimation()
    {
        playerAnimationController.setSpeed(horizontal);
        playerAnimationController.Jump(isJumping);

        if (IsGrounded())
        {
            isJumping = false;
        }
        else
        {
            isJumping = true;
            //Debug.Log("jumping is true");
        }
    }
    public void Jump(bool jump)
    {
        if (!jump)
        {
            return;
        }

        if (jumpsLeft < 1)
        {
            return;

            // TODO: check if player is standing on the ground

            /*
             * if (m_Rigidbody.velocity.y > .001f)
             *      return;
             *
             * if (Physics.Conta( GetComponent<BoxCollider>().)
             * {
             *
             * }
             */
        }
        m_Rigidbody.velocity = new Vector3(m_Rigidbody.velocity.x, 0f);

        if (!m_Grounded)
        {
            jumpsLeft--;
        }
        //else dashCooldown = 0f;
        m_Grounded = false;
        AudioManager.instance.Play(AudioManager.audioSFXJump);
        config.Input.QueueGamepadVibration(PlayerInputMethod.Rumble.VerySmallShortPulse);
        m_Rigidbody.AddForce(new Vector2(0f, m_JumpForce));
        OnJumpEvent.Invoke(this);
        Instantiate(particleJumpPreFab, transform.position + jumpParticleOffset, Quaternion.identity);
        playerStats.jumps++;
        ac.Jump();
        m_WasGrounded = m_Grounded;
    }
예제 #4
0
    private void Update()
    {
        if (Input.GetButtonDown("ToggleView"))
        {
            b_fpp = !b_fpp;
        }

        if (b_fpp)
        {
            tpp.gameObject.SetActive(false);
            fpp.gameObject.SetActive(true);
            cam = fpp;
        }
        else
        {
            tpp.gameObject.SetActive(true);
            fpp.gameObject.SetActive(false);
            cam = fpp;
        }

        if (Input.GetButtonDown("Cancel"))
        {
            toggleEscMenu = !toggleEscMenu;
        }

        if (moveDir.z == 1)
        {
            animationController.movingForward = true;
        }
        else
        {
            animationController.movingForward = false;
        }

        if (moveDir.z == -1)
        {
            animationController.movingBackward = true;
        }
        else
        {
            animationController.movingBackward = false;
        }

        if (moveDir.z == -1)
        {
            animMove = 0.5f;
        }

        if (Input.GetButton("Run") && animationController.movingForward && !animationController.crouched)
        {
            animationController.running = true;
            moveSpeed = Mathf.Lerp(moveSpeed, runSpeed, speedTransition);
            animMove  = 1.5f;
        }
        else if (animationController.movingForward)
        {
            animationController.running = false;
            moveSpeed = Mathf.Lerp(moveSpeed, walkSpeed, speedTransition);
        }

        if (animationController.movingBackward)
        {
            animationController.running = false;
            moveSpeed = Mathf.Lerp(moveSpeed, walkSpeed, speedTransition * Time.deltaTime);
            animMove  = 1f;
        }

        if (!animationController.movingForward)
        {
            animationController.running = false;
            moveSpeed = Mathf.Lerp(moveSpeed, 0f, speedTransition * Time.deltaTime);
            animMove  = 0f;
        }

        if (animationController.movingForward && !animationController.running)
        {
            animMove = 1f;
        }

        if (animationController.movingBackward)
        {
            animMove = 0.5f;
        }

        if (animationController.crouched && animationController.movingForward && !animationController.running)
        {
            moveSpeed = Mathf.Lerp(moveSpeed, crouchSpeed, speedTransition * Time.deltaTime);
            animMove  = 1;
        }

        if (!animationController.movingForward && !animationController.running)
        {
            moveSpeed = Mathf.Lerp(moveSpeed, walkSpeed, speedTransition * Time.deltaTime);
            animMove  = 0f;
        }

        if (groundDistance <= groundedThreshold)
        {
            grounded = true;
            animationController.falling = false;
        }
        else if (groundDistance >= fallingDistance && t_grounded >= 0.25f)
        {
            animationController.falling = true;
            grounded = false;
        }
        else
        {
            animationController.falling = false;
            grounded = false;
        }

        if (toggleEscMenu)
        {
            Cursor.visible   = true;
            Cursor.lockState = CursorLockMode.None;
            return;
        }
        else
        {
            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Locked;
        }

        if (Input.GetButtonDown("Jump"))
        {
            if (grounded)
            {
                animationController.Jump();
                rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
            }
        }

        Ray        ray = new Ray(transform.position, Vector3.down);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, groundedMask))
        {
            groundDistance = hit.distance;
        }



        animationController.grounded            = grounded;
        animationController.animMove            = animMove;
        animationController.animationTransition = animationTransition;

        Move();
    }