Jump to content

Tile collision and gravity


julacariote
 Share

Recommended Posts

Hi everyone,

 

I ran into a problem while prototyping a game. The game is very basic for now: the player is a 32x32 square sprite in a tilemap of 32x32 tiles. The player had to dig trough the dirt tile. Grey tiles (rocks) will fall down if there is no more dirt below them.

post-6203-0-82983900-1400221723.pngpost-6203-0-60375500-1400221728.png

 

As you can see on the screenshots, if the player remove a dirt tile below a rock, this one will start falling down and will also make the player tunneling through the dirt tiles which of course is not intended. I don't understand where the problem might be?

 

In update, I make the player collide with rocks and the dirt tiles.

    update: function() {        // ...        this.game.physics.arcade.collide(this.player, this.layerDirt);        this.game.physics.arcade.collide(this.rocks, this.layerDirt);        this.game.physics.arcade.collide(this.player, this.rocks);               //...    }

I also checked the tiles collisions attributes: collideUp is set to true for the tiles below the player. The player body is set to collide on every faces.

 

Also, the group "rocks" has its property "allowGravity" set to false. It's only when the player remove a dirt tile below a rock that I set the allowGravity of this rock to true. But this is done all in the same frame.

 

Creating the rocks group:

create: function() {        //...        this.rocks = this.game.add.group();        this.rocks.enableBody = true;        this.map.createFromObjects('rocks', 7, 'rock', 0, true, false, this.rocks);        this.rocks.setAll('body.allowGravity', false);        this.rocks.setAll('body.immovable', true); // I don't want the player to be able to push rocks        //...}

It seems that the falling rock gives a velocity to the player which is correct but the player should immediately collide with the dirt tile below him? I tried to play with the TILE_BIAS attribute but still no luck from 40 to 150. The value of gravity does not change anything, the problem is still here with a gravity of 10 or 300.

 

Can anyone help me in the right direction?

Thanks!

 

 

 

Link to comment
Share on other sites

  • 3 years later...
 Share

  • Recently Browsing   0 members

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