Help needed - boxes cannot be stacked - arcade physics

If I stack many sprites on top of each other, they start overlapping, and meld into each other.

To reproduce, paste the following here: https://labs.phaser.io/edit.html?src=src/physics/arcade/simple%20group.js&v=3.24.1

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 800,
    parent: 'phaser-example',
    physics: {
        default: 'arcade',
        arcade: {
            debug: true,
            gravity: { y: 200 }
        }
    },
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('block', 'assets/sprites/block.png');
}

function create ()
{
var group = this.physics.add.group({
    bounceX: 1,
    mass: 20,
    // bounceY: 1,
    collideWorldBounds: true
});
var block1 = group.create(300, 650, 'block').setVelocity(0, 0);

var block1 = group.create(300, 450, 'block').setVelocity(0, 0);
var block2 = group.create(300, 300, 'block').setVelocity(0, 0);
var block3 = group.create(300, 150, 'block').setVelocity(0, 0);
var block4 = group.create(300, 0, 'block').setVelocity(0, 0);

this.physics.add.collider(group, group);
}

(in my usecase, there are quite a few more boxes)

Is arcade physics just not suitable for such thing? Or Is there some setting which would help?

:wave:

Arcade Physics is not really suitable for it. You can try increasing overlap bias or physics fps, but those only mitigate the problem.

You can also try custom separation methods but that can get complicated.

1 Like

Wow thanks!

I actually played with fps, and it does help, when fps was 1000, it stopped overlapping, but was jelly like, and it was working properly when fps is 10000 (but it doesn’t seem very performant;))

But your code works wonderfully! I only plan on top-down motion, and it should suffice. Thank you very much!