Troubles making an intermediate 2D jump

So I’ve coded a few basic platformers with an updated position for movement and stuff, and I wanted to try using the rigid body approach, and it quickly became clear I had no clue what I was doing.
My Question:
How do I make my character jump further (not higher) when they’re running, while making it still feel good? I would love someone to help me understand what the math is doing better. Despite my best efforts, I feel as though I’m still largely guessing or using nonsense.

My Code:
```csharp
**// Jumping while running
if (Input.GetButtonDown(“Jump”) && onGround == true && isRunning == true)
{
isRunning = true;
rb.AddForce(Vector2.up * jumpForce * 1.2f, ForceMode2D.Impulse);

        jumpStarted = true;   
    }

   

    // regular jump
    if (Input.GetButtonDown("Jump") && onGround == true && jumpStarted == false)
    {
        rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
       
        jumpStarted = true;
    }

    // Gravity modifier still
    if (rb.velocity.y < 0)
    {
        rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
    }
    else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
    {
        rb.velocity += Vector2.up * Physics2D.gravity.y * (shortMultiplier - 1) * Time.deltaTime;
    }

    //gravity modifier moving

    if (rb.velocity.x != 0 && isRunning == true)
    {
        rb.velocity += Vector2.up * Physics2D.gravity.y * (shortMultiplier - 1) * Time.deltaTime;

    }

    if (isRunning == true && onGround == false)
    {
        rb.velocity += Vector2.up * Physics2D.gravity.x * .1f * Time.deltaTime;

    }**

```

This video should help:

It doesnt just talk about variable jump heights but also early and late input forgiveness. Very useful stuff

1 Like

I have variable jump heights, I want variable jump distances/lengths :smile:

Depending on what? Like truly just random? Or how long they hold a button down?

I would like the character to jump significantly further in its front-facing direction when running.

So i dont have an exact answer cause there are probably a few ways to do it. But if you have a isRunning bool or something that determines when the player is running, you can have a condition where if you press jump while isRunning is true, it goes further. To do this you can add force not just up but also forward so it makes them go farther horizontally. Thats what i thought of off the top of my head

I have tried this before and now and it doesn’t seem to change the jump at all, I am guessing because of the gravity modifiers?
I’ve tried things along the lines:

 rb.AddForce(Vector2.right * jumpForce * 1.2f, ForceMode2D.Impulse);

rb.AddForce(Vector3.forward * jumpForce * 1.2f, ForceMode2D.Impulse);

neither changed the jump at all.

I just can’t find the answer to ‘how do I jump further not higher’ on anything. EVERYONE just talks about gravity modifiers depending on how long you hold the jump input. Will someone at least explain to me why what I’m asking is so difficult to answer? It’s driving me insane.

If you think its because of the gravity then just increase the jumpForce variable. I would actually create another variable so you can have it differ from the vertical jumpForce. Increase the new one so until you see a noticeable difference.

Additionally, there could be a weird friction issue occurring if the horizontal force gets added immediately and kills the forward momentum because of the ground. You may have to delay the horizontal force a fraction of a second after your vertical force.

1 Like

Thank you for this answer [: It at least gives me things I didn’t think of to look into. I appreciate it. I will update.