0
\$\begingroup\$

As shown here, Paper Mario's jump takes 8 frames go reach the max jump height and 12 frames to get back to the ground. This is pretty unusual, any idea how to jump up that quick with a rigidbody?

I tried to AddForce when rigidbody.velocity.y > 0, but that didn't work out.

Any help would be appreciated, thanks in advance!

//Jump when pressing button and on ground
//jumpForce is a public float variable

if (Input.GetButtonDown("Jump") && isGrounded)
{
    theRB.velocity += new Vector3(0, jumpForce, 0);
}
\$\endgroup\$
1
  • \$\begingroup\$ "I tried to AddForce when rigidbody.velocity.y > 0, but that didn't work out." What specific problems arose? The more you tell us about these issues, the better we can target fixes to solve or avoid them. \$\endgroup\$
    – DMGregory
    Commented Jul 22, 2020 at 21:46

1 Answer 1

1
\$\begingroup\$

When jumping, set a flag (e.g., isJumping) that indicates that the player jump is in action. Then, in update make checks if the vertical velocity is negative (falling down) and player is jumping. If it is:

  • for Rigidbody2D - reduce rigidbody's gravity scale to 0.67 (8 / 0.67 ~= 12).

  • for Rigidbody (3D) - add velocity as such: rigidbody.AddForce(Vector3.up);

When player hits the ground, restore gravity scale to 1 and remove isJumping flag.

\$\endgroup\$
3
  • \$\begingroup\$ Should I set a bool or event to indicate if the player is jumping? Also, how do I change the gravityscale of my rigidbody in script? \$\endgroup\$
    – Spottel
    Commented Jul 23, 2020 at 15:34
  • \$\begingroup\$ Sorry, I didn't see you are using Rigidbody, not Rigidbody2D. Thus, setting gravity scale is not possible. For player jumping indication, I'd say boolean. Setup event only if you want to notify other systems or components about something. \$\endgroup\$
    – eLTomis
    Commented Jul 23, 2020 at 15:47
  • \$\begingroup\$ Note that this means falling from a cliff versus falling from a jump will use different accelerations - if that's not intended for your case, you may want to skip the isJumping check, or apply a downward force on the rising portion of the jump instead. \$\endgroup\$
    – DMGregory
    Commented Jul 23, 2020 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .