public void JumpDown() { if (IsRunning && jumpDownState == JumpDownState.None) { jumpDownState = JumpDownState.Initiated; } }
private void Move(float xSpeed, float highJumpHeight) { _velocity.y = 0; canDoubleJump = true; if (!alive) { normalizedHorizontalSpeed = 0; } var gravity = Physics2D.gravity.y; // we can only jump whilst grounded if (doJump) { doJump = false; // choose jump or double-jump koeficient var jumpKoef = normalizedHorizontalSpeed > 0 ? 1f : 0.75f; _velocity.y = Mathf.Sqrt(jumpKoef * highJumpHeight * -gravity); _animator.SetBool("Grounded", false); } var speedReduce = gravity * Time.deltaTime; if (jumpTime > 0) { speedReduce *= (1 - jumpTime); jumpTime -= Time.deltaTime; } // apply gravity before moving _velocity.y += speedReduce; // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * xSpeed, Time.deltaTime); if (doBounceFromCeiling) { doBounceFromCeiling = false; _velocity.y = 0.1f * gravity; } // if holding down bump up our movement amount and turn off one way platform detection for a frame. // this lets uf jump down through one way platforms if (jumpDownState == JumpDownState.Initiated) { jumpDownState = JumpDownState.WaitingForGround; _velocity.y = 0.3f * gravity; } if (jumpDownState == JumpDownState.WaitingForGround) { jumpDownState = JumpDownState.None; } }