One way platform and double jumping glitch


I’m super new to coding.

I created a one way platform (platform effector 2D) for my character to jump through. Mario style.

But I have a glitch with the code.

  1. Whenever the character’s “ground check” passes through the platform effector 2D’s “surface arc”, the code thinks I’ve touched the ground.
  2. The character hasn’t actually landed on the top of the “platform effector 2D” at this point though.
  3. And if I press fast enough, I can actually get the character to jump as soon as the “groundcheck” passes through the “platform effector 2D”
  4. The result is he catapults himself 2x higher into the air.

Is anyone else having this problem? Is there a work around to this?

Hope this was clear :frowning:

After commenting on your question I think I found a solution :slight_smile: This page shows how to create one way platforms with a script that disables the platform’s collider when the player steps into a trigger. This eliminates the issue of having the “groundcheck” activate because it cannot detect the disabled collider. You have to set up the trigger box manually, but it’s not too big of a con in my opinion. Hope that helps :slight_smile:

EDIT: Although now I realize that since the collider is disabled, if you have enemies or objects sitting on the platform they could fall through :confused:

The only thing you have to do is nullify y velocity of your player’s rigidbody before jumping again.

Something like this (you can see m_Rigidbody2D.velocity = new Vector2(0, 0) )

if (m_Grounded)
                m_Rigidbody2D.velocity = new Vector2(0, 0);

                m_Grounded = false;
                m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
            else if (!doubleJumped) //second jump
                m_Rigidbody2D.velocity = new Vector2(0, 0);

                m_Rigidbody2D.AddForce(new Vector2(0f, m_AdditionalJumpForce));
                doubleJumped = true;