Jump to content

Problem with physics and collision


Geaz
 Share

Recommended Posts

Hi all,

 

I implemented a test with phaser in which i got a 6 columns x 6 rows big field full of blocks.

In the beginning of the "game" the blocks get generated and fall from above onto an immovable sprite. Everything works as expected.

Now, if I remove some of the blocks (kill) the remaining blocks should fall down and new generated blocks should fall on top of the remaining ones.

Here I hit a problem:

In the moment the new blocks fall from above they seem to "push" the remaining ones through each other.

 

I hope you understand my problem.

 

Here is the relevant code I used:

create() {	this.game.stage.backgroundColor = "#000000";	this.border = this.game.add.sprite(0, 896, 'border');	this.border.body.immovable = true;        // Here I create the column groups	 for (var i = 0; i < 6; i++) { 		var group = this.game.add.group();		 group.createMultiple(6, 'motdAssets');		 this.columns.push(group);	}}update() {	for (var i = 0; i < 6; i++) {		this.currentColumn = i;		this.columns[i].forEachDead(this.createRandomBlock, this);               // create new blocks if "old" ones get killed		this.columns[i].forEachAlive(this.worldBlockCollitionTest, this);            // check collision with the bottom border		this.game.physics.collide(this.columns[i], this.columns[i]);                  // all items from one column should collide with each other	}            }private createRandomBlock(block: Phaser.Sprite): void {	var spriteName = this.getRandomSpriteName();	block.reset(this.currentColumn * 128, this.columns[this.currentColumn].countLiving() * - 130);	block.frameName = spriteName;    	block.body.gravity.y = 500;}private worldBlockCollitionTest(block: Phaser.Sprite) {	this.game.physics.collide(block, this.border);}

I hope you are able to help me :)

 

Thanks in advance

Geaz

Link to comment
Share on other sites

Ok, this seems to be a bug with the gravity. It happens, that the internal "block" check fails and applies gravity to elements which are actual blocked. That causes glitches with stacked objects.

 

EDIT: If I dont reuse the objects in the groups (kill and reset), but destroy and recreate them, it seems to work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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