Hello,
I have a slope and a box on it, I tried raising “friction” and “frictionStatic” but no amount will make the box “stick” to the slope and stop sliding down.
Here is a full working example, you can paste it at https://labs.phaser.io/edit.html to try it:
var config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor: '#efefef', parent: 'phaser-example',
physics: {
default: 'matter',
matter: { enableSleep: true, debug: true }
},
scene: {create: create}
};
var game = new Phaser.Game(config);
function create ()
{
var points = [{x: 0, y: 0}, {x: 0, y: 300}, {x: 800, y:300}];
var slope = this.add.polygon(300, 400, points, 0x0000ff, 0.2);
this.matter.add.gameObject(slope, { isStatic: true, shape: { type: 'fromVerts', verts: points, flagInternal: true, friction: 10, frictionStatic: 100 } });
this.matter.add.rectangle(250, 250, 50, 50, { mass: 10, restitution: 0.2, frictionAir: 0.01, friction: 10, frictionStatic: 100 });
}
What parameter do I have to set to stop the box sliding down the slope?
Turned out that it is a matter js bug: https://github.com/liabru/matter-js/issues/613
Any workaround suggestions? Setting velocity to 0, 0 in the update method didn’t work.
This isn’t a fix for your issue, however, in my past experiences with MatterJS, I have found that there are a lot of quirks. These quirks include objects going into and/or going through other physics objects, increasing most variables by too much will make that object act erratically and not how you would expect, using the mouse to move an object that is constrained, makes the object move past it’s constraint and many other issues.
In my opinion, I would opt for another physics engine.
1 Like
I tried several things, but the only way I can find to keep the bounce at the beginning is to add a time delay in the update function:
var config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor: '#efefef', parent: 'phaser-example',
physics: {
default: 'matter',
matter: {enableSleep: true,
debug: true }
},
scene: {create: create,
update:update}
};
var game = new Phaser.Game(config);
function create ()
{
var points = [{x: 0, y: 0}, {x: 0, y: 300}, {x: 800, y:300}];
var slope = this.add.polygon(300, 400, points, 0x0000ff, 0.2);
this.matter.add.gameObject(slope, { isStatic: true, shape: { type: 'fromVerts', verts: points, flagInternal: true,
friction: Infinity,
frictionStatic: Infinity
} });
rec=this.matter.add.image(250,250);
rec.setScale(0.0001);
rec.setBody({
type: 'rectangle',
height:50,
width:50,
restitution: 0.2,
frictionAir: 0.01,
friction: Infinity,
frictionStatic: Infinity,
});
}
function update(){
this.time.addEvent({
delay: 1200,
callback: land,
context: this
});
function land(){
rec.setStatic(true);
}
}
Well, thanks, I have migrated to Phaser 2 + Box2D, it is working nicely as always (but note that Box2D with Phaser is not free).
The only issue was that matter js supports concave polygons and Box2D does not, but I can decompose to triangles myself.