Razvan-Stafan Posted June 21, 2018 Share Posted June 21, 2018 Hello, I have some questions about the physics engine MatterJs. I try to drag&drop an element but I have problem with the collissions between its and the world bounds or the other objects present in the world. This is my my code: preload(): void { this.load.image('background', '../../assets/grid.png'); this.load.image('avatar', '../../assets/avatar.jpg'); this.load.image('bubbles', '../../assets/avatar1.jpg'); } create(): void { this.matter.world.setBounds(200, 200, 10000, 10000); this.tile = this.add.tileSprite(0, 0, 10000, 10000, 'background').setOrigin(0, 0); this.cameras.main.setBounds(0, 0, 10000, 10000); //The item that I want to drag let canDrag = this.matter.world.nextGroup(false); this.image = this.matter.add.image(400, 200, 'avatar', null, { shape: { type: 'circle', radius: 60 } }).setCollisionGroup(canDrag); this.image.setInteractive({ draggable: true }); this.image.setFixedRotation(); let noDrag = this.matter.world.nextGroup(true); //The item that is fix in the world. this.bubbles = this.matter.add.image(500, 500, 'bubbles', null, { shape: 'circle', ignorePointer: true }).setCollisionGroup(canDrag); this.bubbles.setFixedRotation(); //I use this constraint to have a little bounce when the collision appeared this.matter.add.worldConstraint(this.bubbles, 1, 0.2, { pointA: { x: this.bubbles.x, y: this.bubbles.y } }); this.matter.add.mouseSpring({ length: 1, stiffness: 0, collisionFilter: { group: canDrag } }); } My questions: When I drag the item close to the world bounds there are moments that the collision is ignored so my item disappear from the world. When my item collides with the elements present a force is applied and push my item in the other direction Do you have some solutions for my issues ? Link to comment Share on other sites More sharing options...
Richard Poor Posted June 22, 2018 Share Posted June 22, 2018 Hi, I have the exact same problem, the only solution I found is to set the velocity to 0 each update but it's a really dirty workaround. As for collisions I had to create objects in each corners of the screen to avoid my main character passing through... Anyone got better solutions? Thanks, update(): void { this.image.setVelocity(0); } Link to comment Share on other sites More sharing options...
GenericDevelopper Posted June 22, 2018 Share Posted June 22, 2018 Have you tried to plug it off then plug it back ? Link to comment Share on other sites More sharing options...
Recommended Posts