Adding a delay between a key press and applyMovement

I am using Riyuzakisan’s MouseMove to control the dynamic movement of my avatar. I am trying to add a delay between the key press and the applyMovement. When my character jumps, it is an instant reaction and the animation is way out of sync. I want the applyMovement to happen 15 frames after the key press. Does anyone know how to do this?

The applyMovement happens here;

    def state_onGround(self):
        controls = self.core.controls
        
        ### Adjust Speed and Damping ###
        if controls.crouch:
            self.speed *= 0.3
            self.damping = 0.85
        else:
            if controls.run and (controls.forward and not controls.back):
                self.speed = self.runspeed
                self.damping = 0.18
                
            if controls.jump and self.ray:
                self.finalVelocity[2] = self.jumpspeed
                self.run_state = self.state_inAir
            
        if not self.col:
            self.run_state = self.state_inAir
        
        ### Apply ###
        self.assignVelocity()
        self.applyMovement()
        self.limitVelocity()
        self.applyDamping()

and the key press is controlled here;

       
    def main(self):
        key = logic.keyboard.events
        self.jump = key[events.SPACEKEY]

Split the operation into several ones
e.g via states

State “Waiting”
when Jump requested -> State “Preparing”

State “Preparing”
play “prepare jump” action
when “prepare jump” completed -> state "Jumping

State “Jumping”
play “jumping” action
perform movement
when touching ground -> state “Landing”

State “Landing”
play “landing” action
stop movment
when “landing” completed -> state “Waiting”

Hints:
How to: use build-in states - a simple FSM tutorial
How to: create Action sequences with logic bricks - the power of the ActuatorSensor

keypress jump------------and-----------property jump=1
if jump=0-----------------/

if jump min:1 max = (end frame-2)—and---------add 1 to jump

if jump = end frame -1-------and-----------jump=0
if ray-z true ------------------/

if jump = (delay)-----------and------------motion

if Jump = 1------------and------------action jump

I was hoping it would be a simple fix, but I guess not. Thanks guys, I know what I must do.

You should instead adjust the animation. It’s not fun to play when there’s a delay in input.

That wouldn’t work, the reaction is too quick and the animation doesn’t match. I need to give the character time to perform the jump.

Just replace apply motion with
If own jump ==0:
Jump =1

And have the logic loop I posted earlier,
(So the script triggers the logic)
Instead of the keyboard.

looking at that script it looks like a heap-o-states

I use 1 state for moving,

If you feel it’s necessary to have a delay there are ways to do it, but I really do recommend getting rid of it. Next to no games have a delay between pressing jump and being in the air, because it’s very frustrating to play otherwise- if you’re having trouble animating it, look at other games. You’ll rarely, if ever, see a game where the character winds up before jumping, instead it’s implied by having the legs fling out straight down and then lift up gradually, with plenty of secondary motion in the character (hair, arms, etc).

That said, if you really want a delay, probably the simplest way is to output the current frame of the jump animation to a property, and then when the property is equal to whichever frame you want the character to leave the ground on, start the jump.