0
$\begingroup$

for a school project I'm working on a simple game. I want to make the character jump using the KX_CharacterWrapper. (it's necessary to use python since the project is about coding a game)

For the same character, I have a movements script using walkDirection which works fine but the character just won't jump.

import bge


def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner
    me = bge.constraints.getCharacter(own)
    keyboard = bge.logic.keyboard

    me.gravity = 9.81
    me.maxJumps = 1
    cont.jump_speed = 2

    if keyboard.events[bge.events.SPACEKEY] == bge.logic.KX_INPUT_JUST_ACTIVATED:
        me.jump()
main()

I assume the jump function works differently since the rest of the script like gravity works but I couldn't find an example. Thanks for any help.

$\endgroup$
1
  • $\begingroup$ I think cont.jump_speed should be me.jump_speed, but as I did not find jump_speed in the documentation I suggest you visit this video that contains a motion script and works perfectly. $\endgroup$ Commented Mar 22, 2017 at 5:15

1 Answer 1

1
$\begingroup$

Use this:

import bge

def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    keyboard = bge.logic.keyboard.events

    if keyboard[bge.events.SPACEKEY]==1:
        bge.types.KX_CharacterWrapper.jump(bge.constraints.getCharacter(own)) 
        # make sure the object has "Character"  as Physics Type      

main()

I recently discover that piece of code and it works just great. Hopefully works for you as well

$\endgroup$
1
  • $\begingroup$ Thanks for that, it was what I was looking for, and it worked very well. $\endgroup$ Commented Jun 29, 2018 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .