Jump to content

Dash logic not working


zencha
 Share

Recommended Posts

I'm currently adding a "dash" to my infinite runner where the main character can boost forward briefly. Should increase their velocity by X for Y time before resetting it back to 0.

 

Unfortunately it's not working properly. The dash doesn't last the full delay. I think it's being interrupted by the update logic which tells it to set velocity.x to 0 in the air.

 

 

 

Here's the code:

 update: function() {// lose condition        if (this.bird.y > 490)            this.restartGame();//collision checks        game.physics.arcade.collide(this.bird, this.pipes);        game.physics.arcade.collide(this.bird, this.startPipe);        game.physics.arcade.collide(this.bird, this.ground);//reset values while player is touching down. Return if player has not yet jumped.        if (this.bird.body.touching.down) {            this.bird.body.velocity.x = 300;            if(this.jumpCheck == 0) {                return;            }            this.score += 1;            this.labelScore.text = this.score;            this.jumpCheck = 0;            this.dashCheck = 0;            this.dashFinished = true;            game.add.tween(this.bird.scale).to({x: 1, y: 0.8}, 50).to({x: 1, y: 1}, 100).start();        }//while jumping, set player speed to 0 if not dashing.        if(this.bird.body.touching.down == false && this.dashFinished == true){            this.bird.body.velocity.x = 0;        }    },    jump: function(){        if(this.jumpCheck == 0){            game.add.tween(this.bird.scale).to({x: 1, y: 0.6}, 100).to({x: 1, y: 1.4}, 50).to({x: 1, y: 1}, 50).start();            this.bird.body.velocity.y = -550;            this.bird.body.gravity.y = 1500;            game.add.tween(this.bird).to({angle: 360}, 680).start();            this.jumpCheck = 1;            this.dashCheck = 0;        }//double jump        else if (this.jumpCheck == 1){            this.bird.body.velocity.y = -550;            this.bird.body.gravity.y = 1500;            game.add.tween(this.bird).to({angle: 360}, 680).start();            this.jumpCheck = 2;        }        else{            return;        }    },    dash: function(){        if((this.jumpCheck == 1 || this.jumpCheck ==2) && this.dashCheck == 0) {            this.dashCheck = 1;            this.bird.body.velocity.x = 1000;//commenting out game.time.events etc doesn't impact anything. What am I doing wrong here?            game.time.events.add(1000, this.dashFinish, this);        }    },    dashFinish: function(){        dashFinished = true;},
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...