Jump to content

Tile collision issue: gravity is too big, but I need it that way!


thiagoprzy
 Share

Recommended Posts

Hello, everyone.

 

I'm new here and started to work with Phaser just a couple of weeks ago. I have an "already known" issue that some of you should want to kick me in the nuts for opening a topic about it. So, first of all: sorry for asking this question!

 

I've searched (A LOT) about the issue of using Arcade physics with a big gravity value, what causes a random lack of collision between sprites and tiles, but I couldn't find any answer with a solution that maintains the game (and the sprite's fall off) speed and also eliminates the "tile breaking" issue.

 

So, please (pretty please!), does someone have a solution for this, or at least knows another topic or URL that could help me to achieve both?

 

Just as a matter of information, my code is like this:
 

function create() {    game.physics.startSystem(Phaser.Physics.ARCADE);    game.physics.arcade.gravity.y = 2000;	background = game.add.tileSprite(0, 0, 1280, 720, 'background');		map = game.add.tilemap('tilemap'); // Preloaded tilemap	map.addTilesetImage('ground'); // Preloaded tileset	layer = map.createLayer('tile');	layer.resizeWorld();		map.setCollision([1]); //it's the ONLY tile!		player = game.add.sprite(30, 410, 'player');        game.physics.enable(player, Phaser.Physics.ARCADE);	player.enableBody = true;        player.body.collideWorldBounds = true;        player.animations.add('ready', [0,1,2,1], 7, true);	player.animations.add('jump', [2,3,4,5,6], 7, false);	player.body.setSize(72, 175, 52, 25);
function update() {   game.physics.arcade.collide(player, layer);	if (buttonDown && player.body.onFloor())	{		buttonDown = false		player.body.velocity.y = -1020;	}	else if(buttonDown && !player.body.onFloor() && !doubleJump)  	{		player.play('jump');			buttonDown = false;		doubleJump = true;		player.body.velocity.y = -920;	}

The error only happens when "double jump" is triggered. I've already set the gravity down to 1200 (and also correcting the jump's Y negative velocity as well) and the error still happens from time to time (and this speed simply destroyed the dynamic of my game).

 

Thank you for your attention and patience!

Link to comment
Share on other sites

Hello, John! First of all, thank you for your answer!

 

Your solution didn't solved the issue, but helped me to search deeper on the "BIAS world". I found out the property TILE_BIAS, which "strengthen" the tile. So, the solution for my issue was to add the following line:

game.physics.arcade.TILE_BIAS = 40;

40 seems to be the magic number, but I don't know if it solves the issue in all cases (like bigger gravity, for example).

 

Thanks again!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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