Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (!GameManager.instance.gamePaused)
        {
            if (controller.collisions.above || controller.collisions.below)
            {
                velocity.y = 0;
            }

            Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

            if (Input.GetButtonDown("Jump") && controller.collisions.below)
            {
                velocity.y    = jumpVelocity;
                canDoubleJump = true;
                isJumping     = true;
                //	FMODUnity.RuntimeManager.PlayOneShot(FMODPaths.ROBOT_JUMP, GetComponent<Transform>().position);  // jump sound
            }

            sfxVelocity = velocity.y;

            if (Input.GetButtonDown("Crouch"))
            {
                isCrouching = true;
                controller.Crouch();
                StartCrouchingSFX();
            }
            if (!Input.GetButton("Crouch") && isCrouching)
            {
                controller.Uncrouch(ref isCrouching);
                StopCrouchingSFX();
            }

            if (Input.GetButtonDown("Ability1") && ability1 != -1 && !isCrouching)
            {
                abilities[ability1]();
            }
            if (Input.GetButtonDown("Ability2") && ability2 != -1 && !isCrouching)
            {
                abilities[ability2]();
            }
            if (GameManager.instance.playerEnergy <= 0)
            {
                GameManager.instance.ResetLvl();
            }

            float targetVelocityX = input.x * moveSpeed;
            if (isCrouching)
            {
                targetVelocityX *= crouchModificator;
            }
            velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);
            velocity.y += gravity * Time.deltaTime;
            controller.Move(velocity * Time.deltaTime);

            if (controller.collisions.below)
            {
                canDash       = true;
                canDoubleJump = false;
                isJumping     = false;
            }

            if (targetVelocityX != 0 && (!Input.GetButtonDown("Jump"))) // checking if player moving, then executing MovementSFX
            {
                if (!isMoving)
                {
                    //   MovementSFX();
                    isMoving = true;
                }
            }

            if (targetVelocityX == 0 || Input.GetButtonDown("Jump") || sfxVelocity != 0)
            {
                //   MovementSFXStop();
                isMoving = false;
            }

            if (targetVelocityX > 0)
            {
                isRight = true;
            }
            else if (targetVelocityX < 0)
            {
                isRight = false;
            }
            UpdateAnimationParameters();
        }
    }
Example #2
0
    void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }
        bool onGround2 = timeInAir < 0.02f;

        if (!onGround)
        {
            timeInAir += Time.deltaTime;
        }

        if (GameMaster.enabledMovement && (Input.GetKey(KeyCode.DownArrow) || InputMixer.CrouchS))
        {
            if (!isCrouching && !isJumping)
            {
                isCrouching = true;
                controller.Crouch(true);
            }
        }
        else if (isCrouching && controller.CanStand())
        {
            isCrouching = false;
            controller.Crouch(false);
        }

        if (GameMaster.enabledMovement && (Input.GetButtonDown("Jump") || InputMixer.JumpDownS) && !isCrouching)
        {
            if (onGround)
            {
                doubleJumpTimer = 0;
                Jump();
            }
            else if (canDoubleJump)
            {
                velocity.y    = 0;
                canDoubleJump = false;
                Jump();
            }
        }
        if (GameMaster.enabledMovement && (Input.GetButtonUp("Jump") || InputMixer.JumpUpS) && isJumping)
        {
            velocity.y *= 0.4f;
            isJumping   = false;
        }
        if (jumpTimer < timeToJumpApex)
        {
            jumpTimer += Time.deltaTime;
        }
        if (jumpTimer >= timeToJumpApex)
        {
            isJumping = false;
        }
        if (GameMaster.enabledMovement && (Input.GetButton("Jump") || InputMixer.JumpS) && !onGround && !isDashing && !isJumping && !isCrouching)
        {
            doubleJumpTimer += Time.deltaTime;
            if (doubleJumpTimer > 0.1f)
            {
                floatGravity = true;
            }
        }
        else
        {
            doubleJumpTimer = 0;
            floatGravity    = false;
        }
        Vector2 input;

        if (GameMaster.enabledMovement)
        {
            input = new Vector2(Mathf.Clamp(Input.GetAxisRaw("Horizontal") + InputMixer.HorizontalS, -1, 1), Input.GetAxisRaw("Vertical"));
        }
        else
        {
            input = new Vector2(0, 0);
        }

        //совршить рывок
        if (GameMaster.enabledMovement && (Input.GetKeyDown(KeyCode.LeftShift) || InputMixer.DashDownS) && sinceLastDash >= timeBetweenDashes && !isCrouching && stamina > 0)
        {
            isDashing = true;
            stamina  -= 1;
            StartCoroutine(DecreaseSlider(sliderSTA, .2f, stamina / 10));
        }
        if (!isDashing)
        {
            sinceLastDash += Time.deltaTime;
        }
        else
        {
            sinceLastDash = 0;
        }
        if (isCrouching)
        {
            velocity.x = input.x * crouchSpeed;
        }
        else if (isDashing && dashTime <= maxDashTime)
        {
            dashTime  += Time.deltaTime;
            velocity.x = (input.x != 0)?(input.x * dashSpeed):((facingRight)?(dashSpeed):(-dashSpeed));
        }
        else
        {
            velocity.x = input.x * moveSpeed;
            isDashing  = false;
            dashTime   = 0;
        }
        if (!isCrouching && (Input.GetKeyDown(KeyCode.C) || InputMixer.Skill3DownS))
        {
            ult.Ultimate(facingRight, skill3modifier);
        }

        if (onGround && !isCrouching && !isDashing && weapon.CanWalk())
        {
            if (GameMaster.enabledMovement && (Input.GetKeyDown(KeyCode.Z) || InputMixer.Skill1DownS) && stamina > 0)
            {
                weapon.Hit1(facingRight, skill1modifier);
                stamina -= 1;
                StartCoroutine(DecreaseSlider(sliderSTA, .2f, stamina / 10));
            }
            else if (GameMaster.enabledMovement && (Input.GetKeyDown(KeyCode.X) || InputMixer.Skill2DownS) && stamina > 0)
            {
                weapon.Hit2(facingRight, skill2modifier);
                stamina -= 2;
                StartCoroutine(DecreaseSlider(sliderSTA, .2f, stamina / 10));
            }
        }

        if (!weapon.CanWalk())
        {
            velocity.x = 0;
        }

        if (velocity.x != 0 || isCrouching || isDashing || !onGround)
        {
            weaponRenderer.enabled = false;
        }
        else
        {
            weaponRenderer.enabled = true;
        }



        animator.SetBool("isMoving", velocity.x != 0);
        animator.SetBool("floatGravity", floatGravity);
        animator.SetBool("isJumping", isJumping);
        animator.SetBool("isDashing", isDashing);
        animator.SetBool("isCrouching", isCrouching);
        animator.SetBool("onGround", onGround2);
    }
Example #3
0
    /// <summary>
    /// Maps player inputs into movement and calls appropriate commands from the controller.
    /// </summary>

    void MoveByInput()
    {
        // Get the current axis values and add them to a vector.
        FindAxes();

        UpdateFacingDirection(input);

        bool crouching;

        bool isJumping = false;

        if (Input.GetKey("s") || Input.GetKey("down"))
        {
            crouching = true;
        }
        else
        {
            crouching = false;
        }

        controller.Crouch(crouching);

        if (IsStill() && !SpacePressed())
        {
            // If we arent moving then just apply gravity normally.
            controller.ApplyGravity(ref input, true);

            animator.SetBool("isWalking", false);
        }
        else
        {
            controller.ApplyGravity(ref input);

            if (SpacePressed())
            {
                if (controller.Collisions.isBelow)
                {
                    controller.Jump(ref input);
                    SoundManager.instance.PlaySingle(jumpSound);
                }
            }

            if (controller.Collisions.isBelow && input.x != 0)
            {
                animator.SetBool("isWalking", true);
            }

            controller.ApplyMovement(input);
        }

        if (!controller.Collisions.isBelow)
        {
            isJumping = true;
        }

        animator.SetBool("isJumping", isJumping);



        // If anything is listening for player movement then invoke the delegate.
        if (playerMoved != null)
        {
            playerMoved.Invoke();
        }
    }