void ApplyJumping() { //Prevent jumping too fast after each other if (lastJumpTime + jumpRepeatTime > Time.time) { return; } if (IsGrounded()) { //Jump //Only when pressing the button down //With a timeout so you can press the button slightly before landing if (canJump && Time.time < lastJumpButtonTime + jumpTimeout) { verticalSpeed = CalculateJumpVerticalSpeed(jumpHeight); SendMessage("DidJump", SendMessageOptions.DontRequireReceiver); charAvatar.Jump(); } } }
Vector3 ApplyGravityAndJump() { Vector3 verticalDir = Vector3.zero; if (m_keyJump && !m_isJumping && m_jumpTimer < Time.time) { //Jump height is 35% of total height verticalDir.y += CalculateJumpVerticalSpeed(m_colliderControl.MaxHeight * 0.35f); m_isJumping = true; m_keyJump = false; m_avatar.Jump(); } bool isGrounded = IsGrounded(); if (isGrounded) { //Are we grounded and were we jumping? Then we must've just landed if (m_isJumping) { m_jumpTimer = Time.time + m_minTimeBetweenJumps; } m_avatar.SetCurGroundHeight(this.gameObject.transform.position.y); //We're on the ground, so we're not jumping m_isJumping = false; } else { m_keyJump = false; verticalDir.y -= (m_gravity * Time.deltaTime); } return(verticalDir); }