Jump to content

Wall jump ideas


zxxz
 Share

Recommended Posts

Hey, 

 

I am trying to work out how I would implement a wall jump in a game. I have made a call like so:

this.game.physics.collide(player, layer, this.collideLayer, null, this);

And then have tried to implement ideas in the collideLayer function but I guess that the sprite movements in the update call would just override anything I put there? I'm not sure if this is the best way to go about it? 

 

Thanks for any help or ideas! 

Link to comment
Share on other sites

Are you talking about the wall jump you are able to do in mario for example?

 

If so, I implemented it this way:

 

Walljump from a wall to the left:

 

You (the player) need to be pressing the button to move left, the sprite needs to touch the wall to the left (touching.left = true), but also has to be in the air ( touching.down = false ) and if you (the player) now also press the jump button, the sprite gains negative y velocity and some positive x velocity.

 

Samething (but with touching.right, and negative x velocity)  goes for walls to your right.

 

It's all some if-clauses in the update() function.. looks like this:

 

   if (this.cursors.up.isDown && !this.sprite.body.touching.down ) {      if (this.cursors.left.isDown && this.sprite.body.touching.left) {        this.sprite.body.velocity.x = 450;        this.sprite.body.velocity.y = -400;      }      if (this.cursors.right.isDown && this.sprite.body.touching.right) {        this.sprite.body.velocity.x = -450;        this.sprite.body.velocity.y = -400;      }    }
Link to comment
Share on other sites

Yeah that's the kind of wall jump I mean. Thanks for your solution! I tried something similar to this before but it seems that as the if statement checks if the body is touching the wall, the velocity on the body.x will only move 450 and then stop and fall vertically as the sprite is not touching the wall any more. I have got a solution working but not sure if it is really ideal. 

this.game.physics.collide(player, layer, this.collideLayer, null, this);
 collideLayer: function (player, layer) {        if(player.body.touching.right)        {            if(upKey.isDown)            {                inWallJump = true;                player.scale.x = player.scale.x * -1;                player.body.velocity.y = -300;                player.body.acceleration.x = -20000;            }             }        else if(player.body.touching.left)        {            if(upKey.isDown)            {                inWallJump = true;                player.scale.x = player.scale.x * -1;                player.body.velocity.y = -300;                player.body.acceleration.x = 20000;            }           }        else            {                player.body.acceleration.x = 0;            }    },

And then I use the inWallJump boolean on the update keys to make sure the sprite cannot really move while in a wall jump. Also i'm not sure why it needs 20000 acceleration but it seems to give a decent jump.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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