The interaction of two dynamic bodies in arcade physics

Hi everyone!
I have one static body - blue rectangle, and two boxes with dynamic bodies. The first box falls to the floor and stands still, while the second (upper) box falls to the first one and perform “micro jumps” - the property box.body.touching.down become true and false in cycle and debug system draws green small down velocity vector.
*Boxes must be draggable by mouse, so i make it with dynamic body.
Can anyone gime me a hint why this happends? How to eliminate this effect?

Here is the main code:

let floor = this.physics.add.existing(this.add.rectangle(0, this.game.config.height*0.95, this.game.config.width, this.game.config.height*0.05).setOrigin(0, 0), true);
this.box1 = this.physics.add.image(this.game.config.width/2, this.game.config.height*0.66, 'box');
this.box2 = this.physics.add.image(this.game.config.width/2, this.game.config.height*0.33, 'box');
this.physics.add.collider([this.box1, this.box2], floor);
this.physics.add.collider(this.box1, this.box2);

Thanx!

Solved the problem with “customSeparateY”.

Link to the example

Source post at this forum

The solution of my case as it follows:

this.box2.body.customSeparateY = true; // this is upper box2

this.physics.add.collider(this.box1, this.box2, (box1, box2) => {
	const b1 = box1.body;
    const b2 = box2.body;
    if (b1.y > b2.y)  {
       b2.y += (b1.top - b2.bottom);
       b2.stop();
    }
    else {
       b1.y += (b2.top - b1.bottom);
       b1.stop();
    }
});		
1 Like