What should i put??

I have been trying to make ralph jump and i was looking through my code and im trying to set what happens when i hit the spacebar (which is supposed to make ralph jump)

here is code

        # If a move-key is pressed, move ralph in the specified direction.

        if (self.keyMap["left"]!=0):
            self.ralph.setH(self.ralph.getH() + elapsed*300)
        if (self.keyMap["right"]!=0):
            self.ralph.setH(self.ralph.getH() - elapsed*300)
        if (self.keyMap["forward"]!=0):
            backward = self.ralph.getNetTransform().getMat().getRow3(1)
            self.ralph.setPos(self.ralph.getPos() - backward*(elapsed*5))
        if (self.keyMap["jump"]!=0):

What do i put after the bottom line???

Please HELP!!!

If you need any more information i can post

Please put any suggestions you have. I will try them all and see which one works

As you want some sort of gravity (jumping depends on gravity) i suggest you add a variable zVelocity.

If you press the space button, you set the zVelocity to some value (lets say 10).
Every step you:

  • decrease the zVelocity by 10*globalclock.getDt()
  • move the character by zVelocityglobalclock.getDt() (relative to itself (self.character.setZ( self.character, self.zVelocityglobalClock.getDt())

The tricky part is to set the character on the ground once it reaches it again.

  • eigher know the height of the ground and the character
    • if groundheight > characterheight
      • characterHeight = groundHeight
  • send a ray down from the character and check the length of it. (the ray should start above the feet position of the character, else it may fall trought the ground)
    • if the character reaches the ground, set it on it…

(this are just some thought’s, they may work or not)

thanks for the help…i will try that