I’ve recently dived into moving over from logic bricks to Python in order to clean up my rather messy workflow, and have created a 2D platformer test to show what I’ve been learning. One of the things I wanted to do that I learned how to do with logic bricks was create a double jump that was granted upon collision with another object. Upon collision with the other object it’s removed, and a property called hasDoubleJump is applied to the player character. Now, the double jump works… But it stacks on top of the initial jump as well. I was wondering if there was a way to put in a delay between the first jump and the second entirely within the Python script. Basically what happens is that the following two “if” statements activate at the same time, and instead I want the first to activate, then after a short while the second. That way the player can jump, then double jump, Symphony Of The Night style.
if aButton.positive and onGround.positive:
cont.activate(“jump”)
if notOnGround.positive and hasDoubleJump.positive:
cont.activate(“jump”)
I gave an answer, but it wasn’t correct. I think what you need is more like :
while notOnGround.positive :
if hasDoubleJump.positive :
cont.active("jump")
Though I am not a blender or game developer, so using a while here might break things. Short of this being just “wrong” it should allow the double jump condition to only apply when in the air.
Yeah, that’s basically what I already have. The “and” modifier already states that if the player’s not on the ground that they can double jump. The problem is it’s activating as soon as they stop touching the ground, within a single logic tic of onGround deactivating. I wanted it to wait at least thirty tics before it allows the player to activate the double jump.
all you need is one property. set it to integer 0.
when you jump, check if ground(and/or property is 0) and jump key, then set property to 1. if hasDoubleJump, set property to 2. if jump key and property is 2, jump and set property to 3.
if aButton.positive and onGround.positive:
cont.activate(“jump”)
elif notOnGround.positive and hasDoubleJump.positive:
cont.activate(“jump”)
added EL before the second IF statement. But this will result also in jumping automatically, so we need to handle it in an other way, first check the button press, then check on ground, then if not on ground and collision.positive handle double jump.
if aButton.positive:
if onGround.positive:
cont.activate(“jump”)
elif hasDoubleJump.positive and not OnGround.positive:
cont.activate(“jump”)
Ah sorry forgot about that, you can use an timer property, and check the time between the jumps
if own[‘timer’] >= 1: #activate second jump
so we get
if aButton.positive:
if onGround.positive:
#set timer to 0
own['timer'] = 0
cont.activate(“jump”)
elif hasDoubleJump.positive and not OnGround.positive and own['timer'] >= 1:
cont.activate(“jump”)
use a property ‘Jump’ this property is used to also sequence the animations.
jump = own['Jump']
if jump==0 and JumpKey.positive:
applyForce
jump=1
#begin jump state
#rising state
elif jump>0 and jump<=29:
jump+=1
#top of arc
if jump >= 15 and own.localLinearVelocity.z < -.05 and jump<31:
jump=31
#falling loop
if jump > 31 and jump < 49:
jump+=1
if jump ==50:
jump=31
#exit fall loop condition
rayEnd = own.worldPosition + (own.worldLinearVelocity * multi)
ray = own.rayCast(rayEnd, own.worldPosition, 0, '', 0,0,0)
#we can do fancy stuff later for if you hit a wall stick to it etc by comparing hitpoint to local
if ray[0]:
jump=51
#play landing animation
if jump>=51 and jump <= 64:
jump+=1
#reset jump
if jump== 65:
jump=0
own['Jump']=jump
This sent the cube flying off into space somewhere, far beyond the reaches of any telescope. I think it’s just activating cont.activate(“jump”) in a loop over and over again as soon as the game engine starts.
Alright, thanks for all the suggestions guys. Really helpful. I combined a few of the suggested methods to create this interesting abomination that works wonderfully:
if notOnGround.positive and hasDoubleJump.positive and aButton.positive and own[‘jumpTime’] > 0.5:
cont.activate(“jump”)
Your solution will either meet the condition immediatly or enter an endless loop.
It is a pretty dangerous to define loops with conditions that do not change while processing the Python controller. The game will not continue until the Python controller ends. The processing time of your python code needs to be as short as possible.