You have it so currently you set jtimer to 0 at the beginning of every frame, so of course it only gets as high as 1; because then the next frame comes around and you reset it again. Try putting “own.jtimer = 0” inside the first if statement. However, once the timer reaches 5 it’ll hold there, because you have 2 if statements that will both be true, one of which will add 1 to the timer and the other which will subtract 1. If you get that flaw worked out you’ll have a rather unnatural looking jump, where the character moves up at a constant speed and then suddenly is moving down at a constant speed. What I recommend is to let the physics engine deal with the character in air; all you need is to test if the character is currently on the ground, and if the player has pressed the jump key. Then apply a lot of upward force, or set the Z velocity (but only for one frame!) and let gravity do the rest. You’ll have a much simpler and better looking result.
here’s a simpler way of achieving a jump. it’s Captain Oblivions suggestion translated to code.
import bge
controller = bge.logic.getCurrentController
player_obj = controller().owner
keyboard = bge.logic.keyboard
keyjustactive = bge.logic.KX_INPUT_JUST_ACTIVATED
# create a collision logic brick called Floorcollision
# which detects when the character is touching the floor
# an always sensor is required as well
floor = controller().sensors["Floorcollision"]
# change the z value(500.0) depending on how high you want the jump
if keyboard.events[bge.events.SPACEKEY] == keyjustactive and floor.positive:
player_obj.applyForce([ 0.0, 0.0, 500.0], True)
please note this is a 2.55 script though it shouldn’t be difficult to change to 2.49
After I posted this thread, I removed my jumping python code (1st post). Then I made the same thing (like both of you suggested and coded), using only logic brick. It is working fine. But I never thought to code it in python.
I will try to convert it :yes:.
Thank you for the reply
Regards
EDIT: Just made it. Result is same like logic brick :yes:.
I made yesterday a blend file with your script (text). And one simple script (text.001). But yesterday the forum was so slow that I wasn’t able to upload the file. Jump.blend (141 KB)