Having a noob problem with jumping

Hey guys, I’m new at this coding business and wanted to learn by making a simple platformer, after much research and struggle I got my character to move, but now I can’t get him to jump.

67618-jumpcode.png

At first I had something really complicated and through research threw that all out and got here, I don’t understand why I am not jumping though, I tried both the button and input manager thing, and then when that didn’t work I decided maybe to try keycode. My though was that it is close enough to my movement code and that works so maybe its not reading my button press correctly?

Any advice would be appreciated

A few things…

First, if you ever wonder if a given piece of code is even being executed, simply add a Debug.Log() statement at an appropriate place. If it doesn’t show up in the log console, you never got to it. So, for instance, if you wonder if this is executing:

if (Input.GetKeyDown(Keycode.Space))
{
    // some code here
}

Change it to this:

if (Input.GetKeyDown(Keycode.Space))
{
    Debug.Log("input detected");
    // some code here
}

If you don’t see the “input detected” message in the console, you’re not getting inside the “if” block.

Now, regarding your specific issue…

I don’t see anything wrong with your if block, so I think it’s probably executing (though, try the above to verify that). You might try specifying the variations of the 2nd (ForceMode2D) argument to AddForce to see what results that gives.

Additionally, since the force added is related to the mass of the rigidbody, I wonder if there’s a problem with mass value? You might fiddle with that too to see what results you get.

Well i used the same code in my videos and i integrate it with double jump look this pls subscribe
Jump