The interaction of two dynamic bodies in arcade physics

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