Jump to content

Weird Physics Problem When Jumping From A High Place


stnight99
 Share

Recommended Posts

Hello Guys,

 

I have encountered a weird problem on a sprite character jumping off from a high place and whenever it falls - it should hit the ground layer, but it doesn't, it just go through it even the ground layer is declared as a solid surface, I recorded it - just check this link: https://drive.google.com/open?id=0B7e3g0f7wFCPTU9feXRObnlBREk

 

and below is my code:

var playState;playState = {  create: function() {    this.leftButton = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);    this.rightButton = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);    this.upButton = game.input.keyboard.addKey(Phaser.Keyboard.UP);    game.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP]);    game.physics.startSystem(Phaser.Physics.ARCADE);    this.bg = game.add.tileSprite(0, 0, 1024, 1025, 'bg_talltrees');    this.bg.fixedToCamera = true;    this.map = game.add.tilemap('level0');    this.map.addTilesetImage('sheet', 'sheet');    this.map.addTilesetImage('sheet_grass', 'sheet_grass');    this.map.addTilesetImage('other_objects', 'other_objects');    this.ground = this.map.createLayer('ground');    this.building = this.map.createLayer('building');    this.building_door_windows = this.map.createLayer('building_door_windows');    game.physics.arcade.enable(this.ground);    this.map.setCollisionBetween(1, 1000, true, 'ground');    this.ground.resizeWorld();    this.startpoint = game.add.group();    this.map.createFromObjects('startpoint', 148, 'signRight', 0, true, false, this.startpoint);    this.sPoint = this.startpoint.getFirstAlive().position;    this.player = game.add.sprite(this.sPoint.x, this.sPoint.y, 'player');    game.physics.arcade.enable(this.player);    this.player.anchor.setTo(0.5, 0.5);    this.player.body.gravity.y = 2000;    this.player.animations.add('walk', [0, 1, 2, 3, 4, 5, 6, 7], 10, true);    game.camera.follow(this.player);  },  update: function() {    this.player.body.velocity.x = 0;    game.physics.arcade.collide(this.ground, this.player);    if (this.upButton.justDown && this.player.body.onFloor()) {      this.player.body.velocity.y = -800;      this.player.animations.play('jump');    }    if (this.leftButton.isDown) {      this.player.scale.x = -1;      this.player.body.velocity.x = -150;      this.player.animations.play('walk');    } else if (this.rightButton.isDown) {      this.player.scale.x = 1;      this.player.body.velocity.x = 150;      this.player.animations.play('walk');    } else {      this.player.animations.stop('walk', true);    }  },  render: function() {}};
Link to comment
Share on other sites

I'm just guessing here... but I bet you're experiencing tunneling. That means that the velocity of the object is some factor greater than the size of the thing you're trying to collide with. In this instance, if the tile is 16px high and the velocity is higher than 960 px/sec there's a good chance the physics engine will miss the collision.

 

To combat that in Phaser, you can either change the physics variables you're using (gravity, max velocity, etc) or you can set the sprite.body.tilePadding property to make up the difference.

Link to comment
Share on other sites

Also, there's a magic property to use which very often solves the problem (and could enable you to go back to 800 velocity) : 

this.game.physics.arcade.TILE_BIAS = 40;

Tweak it to use a value which works for you.

 

I don't even know what that does, but it sure has solved this very issue for me a couple of times already...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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