Jumping

Ok so here is my logic behind jumping. My player is a cube with box collision bounds and a mass of 500. When I hit the spacebar I give the player object a linear velocity of 5 in the Z direction. If I rapidly press spacebar the player just keeps floating up and up. How can I correct this so I have normal jumping physics?

Well, in reality, one cannot jump if they’re not touching the ground to push against. So, just use a collision / touch sensor on the ground, and use that in combination with the keyboard sensor (an AND controller).
This should fit your needs

There are several possible solutions for addressing this:

  1. Set a delay for how frequently the player can jump (this would be easy to implement, but would probably be annoying to the player)
  2. Only allow the player to jump if they are in contact with the ground (probably the most involved to implement, but probably the most accurate, also the constant collision checking will take more resources than most of the other methods)
  3. Only allow the player to jump if their z velocity is zero (this happens twice, on the ground and at the peak of their jump. With a proper threshold this is easy to implement and it is hard for the player to achieve a double jump)
  4. Only allow the player to jump if their z position is below a certain number (this would only work if your world was nearly flat, which is unlikely)

I would recommend going with either option 2 or 3. Those two options will work in the most number of situations. If you are ok with the slight possibility of a precise player double jumping, then I recommend number 3. Not sure if number 3 can be done with just logic bricks though. I am sure I have seen logic brick only set ups for option number 2 though.

That’s the simplest method, but could also lead in you being able to jump if you’re in the air and touch a wall (unless you’re using the rather basic technique of splitting your walls and ground into separate objects)

Otherwise, you might need a ray sensor as a result to make sure the player is on the ground.

This is basic jumping, you can easily get more advanced. (and more reliable in fast-paced situations or on slopes), by increase the length of the ray, create a property storing the length as well as one returning the face normal of the ground, and use the property to tweak the required threshold for how long the ray can be to allow the jump). It would be a bit more complex, but smarter (would be able to work reliably and as expected even with the walls and floor as one object).

Also, you can create an invisible plane object that your player will detect and use as reference if he is able to jump or not.