matter-js
matter-js copied to clipboard
After call setVertices on the body, his collisions are not updated
Used dependencies
-
"matter-js": "^0.18.0"
Background
I updated body vertices with call setVertices but after the call, his collisions are not updated, so other object does not fall. Maybe I skipped some basic principles of using matter.js so I present the short version of using them if this is not enough I will create a separate working example.
// Init engine
const engine = Engine.create();
const runner = Runner.create();
Runner.run(runner, engine);
// Add a circle for check collision
const circle = Bodies.polygon(300, 100, 5, 12, {
frictionAir: 0, friction: 0.0001, restitution: 0.6
});
World.add(engine.world, circle);
// Create a body from vertex (parsed from SVG path)
// Original vertexes
const originalMapVertices = [[..]];
const ground = Bodies.fromVertices(400, 400, originalMapVertices, { isStatic: true }, true);
World.add(engine.world, ground);
// On click to update vertices for polygon
const newVertices = [...]
Body.setVertices(ground, newVertices);
Before updating vertices:
After updating vertices (called setVertices):
Question
Why another physic body like a small polygon does not fall in the updated rectangle? Continues to stay in the same place, given that the vertices have already been updated.
Thanks for the detailed report.
Could you try using Engine.clear(engine)
after using Body.setVertices
?
Also do you have poly-decomp
set up in your project? See docs for Bodies.fromVertices for more info.
Thanks for the answer! I tried to use Engine.clear
but it does not help. I used the last version of poly-decomp
.
I created the sandbox with dynamic updating vertices.
Sandbox control:
- Left click - update vertices
- Right click - add a circle