Jump to content

player.body.touching.down not working


Recommended Posts

Hello, i'm new in this forum, i started to try Phaser and got a problem, i created a player.body and a ground.body but i cant make my player jump when it is touching the ground.


game.prototype = {
  create: function() {
    this.ground = this.add.sprite(0, this.game.height - 128, 'ground');
    this.player = this.add.sprite(150, 0,  'player');

    this.player.y = this.game.height - (this.player.height / 2) - this.ground.height;

    this.physics.arcade.enable([this.player, this.ground]);

    this.player.body.gravity.y = 1000;

    this.ground.body.immovable = true;
  update: function() {
    if (this.spaceKey.isDown || this.input.activePointer.isDown)

    this.physics.arcade.collide(this.player, this.ground);
  checkJump: function() {
    if (this.player.alive && (this.player.body.touching.down || this.player.body.onFloor())) {
	  // Add a vertical velocity to the player
	  this.player.body.velocity.y = -580;

Maybe i'm missing something.

Thanks for your help in advance.

EDIT: My sprites are loaded in another file, but there is no problem with that.

EDIT2: The game has no problem when i comment     this.physics.arcade.collide(this.player, this.ground); , but as you will know, it collides with the world's bottom and the jump method triggers

Link to comment
Share on other sites

I went through this issue about a week ago, I figured it out by pulling up my player sprites debug information. In the picture below you can see there is two flag variables you can use, one is 'touching' the other is 'blocked'. Now in my situation it may be because I'm using a tilemap and not another sprite as the ground but I had to use this.body.blocked.down; for it to detect the floor, or alternatively this.body.onFloor();  Are you using a tilemap? This may be the problem, other than that from what I understand the 'touching' flag variable is for checking two sprites, and your code looks like it should be working fine. So I'd recommend pulling up the sprite debug info and seeing if one of them are active.


Link to comment
Share on other sites

LTNGames i haven't practice with tileset yet, but i found the solution to my problem in another post,

 i could have never imagined i should checked for collisions before checking for inputs, everything i've read from gamedesign pattern is the order "1) game input, 2) game logic, 3) game render", so this was very surprising to me. Thanks anyway for your help.

Sorry if i type the wrong way, english is not my native language.

Link to comment
Share on other sites

  • 1 year later...

oh hell, this solved my problem as well, i was having a similar problem while using tilemaps. I also couldn't have imagined that the checking input - collision order would be relevant. thank you for posting it :lol:

It still doesnt solve the issue about touching the ground tho, my debug still displays that the sprite is blocked from the bottom but isnt touching the ground, even when its on a collisionable layer.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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