Jump to content

Can't jump and walk at the same time

Recommended Posts

Hi, I'm programming a simple platformer game, and I'm programming and setting the movement of the player. Here's my update function:

update: function () {
        game.physics.arcade.collide(this.player, this.platform);
                this.player.body.velocity.x= 200;
                this.player.animations.play('correr', 5, true);
            else if(this.cursor.left.isDown){
                this.player.body.velocity.x= -200;
                this.player.animations.play('correr', 5, true);
            else if(this.jump.isDown && this.player.body.wasTouching.down) {
                this.player.body.velocity.y= -400
            else if((this.cursor.right.isDown || this.cursor.left.isDown) && this.jump.isDown){
                this.player.body.velocity.x= 200;
                this.player.body.velocity.x = 0;
                this.player.frame = 4;

Everything works fine, but in my last else if is suppose that the player should jump and walk, but it doesn't work! My intention is the player could jump while walking pressing the jump key + left or right key, for now I just can jump first and then walk.

I don't know why this las if else it isn't being executed, because I tried to move it in the first if clause and it worked perfectly, but I can't realise about the error.

Thanks for helping.

Link to post
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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...