// This function is called every fixed framerate frame. void FixedUpdate() { // If the player should jump... if (jump) { // If the player is jumping down a platform and is doing the first jump... if (player.jumpDown && jumps == doubleJumping.totalJumps) { // ... add a small Y force. player.rigidbody.AddForce(new Vector2(0f, 200f)); // If the player is on a platform... if (player.OnPlatform()) { // Set the moving platform to null. player.UnstickFromPlatform(); } // Reset the jumping variables. ResetJumpVars(); // Reset jumpDown. player.jumpDown = false; // Stop the player from jumping. return; } // If this is the initial jump... if (initialJump) { // Check if the player is running when the jump is being performed. walkingOnJump = player.walking; // When double jumping, set Y velocity to 0 to make sure the jump force is applied correctly. if (doubleJump) { player.SetYVelocity(0); } // Decrease total jumps allowed with 1. jumps--; // If the player is on a moving platform and should not keep the speed when jumping from a moving platform... if (player.OnMovingPlatform() && !player.KeepSpeedOnJump()) { // Set the X velocity to 0. player.SetXVelocity(0); } } // Get the jump factor. float jumpFactor = player.GetJumpFactor(); // If you need to hold the Jump input to jump higher... if (jumpType == JumpType.HoldToJumpHigher) { // When there is an initial jump... if (initialJump) { // ... set the y velocity to the player's initial jump value. float yVel = jumpFactor * (doubleJump ? holdToJumpHigher.initialDoubleJump : holdToJumpHigher.initialJump); // If the player is on a moving platform... if (player.OnMovingPlatform()) { // ... get the current platform. GameObject platform = player.GetPlatform(); Rigidbody2D platformRigidbody = platform.GetComponent <Rigidbody2D>(); // If the platform's Y velocity is greater than 0... if (platformRigidbody.velocity.y > 0) { // ... make sure the y velocity of this platform is taken into account when jumping. yVel += platformRigidbody.velocity.y; } } // If the player is on a platform... if (player.OnPlatform()) { // Set the moving platform to null. player.UnstickFromPlatform(); } // Make sure the player's velocity is set. player.SetYVelocity(yVel); // Set initialJump to false. initialJump = false; // When the jump button is being pressed and the timer isn't finished yet... } else if (Input.GetButton("Jump") && jumpTimer > 0) { // ... decrease the timer's value. jumpTimer -= Time.deltaTime; // Set the Y Force for the player. player.rigidbody.AddForce(new Vector2(0f, jumpFactor * (doubleJump ? holdToJumpHigher.doubleJumpForce : holdToJumpHigher.jumpForce))); // When the timer is finished or the jump button isn't being pressed... } else { // ... reset the jumping variables. ResetJumpVars(); } // Or else if you need a single press to perform a jump... } else { // Add a vertical force to the player. player.rigidbody.AddForce(new Vector2(0f, jumpFactor * (doubleJump ? singlePressToJump.doubleJumpForce : singlePressToJump.jumpForce))); // If the player is on a platform... if (player.OnPlatform()) { // Set the moving platform to null. player.UnstickFromPlatform(); } // Reset the jumping variables. ResetJumpVars(); } } }
// This function is called every fixed framerate frame. void FixedUpdate() { // Cache the player speed and horizontal input. float speed = player.GetSpeed(); // Make the player performs a boomerang wall jump. if (boomerangJump) { // Perform the jump once. if (performBoomerangJump) { performBoomerangJump = false; boomerangDirection = player.hor; player.SetYVelocity(0); PerformWallJump(); } // If the boomerang wall jumping direction is different, stop the boomerang wall jump. if (player.hor != boomerangDirection) { boomerangJump = false; // Or else set the speed in the opposite direction. } else { player.SetXVelocity(speed * (player.hor * -1)); } } else { // Set the velocity to make the player run on a wall. if (wallRunning) { if (!wallRun.infiniteRun && wallRun.runSlowdown) { player.SetYVelocity(runSlowdownSpeed); } else { player.SetYVelocity(wallRun.runSpeed); } } // Set the velocity to make the player slide down a wall. if (wallSliding) { if (wallSlide.slideSpeedup) { player.SetYVelocity(-slideSpeedupSpeed); } else { player.SetYVelocity(-wallSlide.slideSpeed); } } // Make the player stuck on the wall to wall jump. if (stuckToWall) { player.SetXVelocity(0); player.SetYVelocity(wallJump.wallStickVelocity); } } }