Take a look at the shape I'm anticipating. The vertices along the edge outline the points.
https://i.sstatic.net/YpQrR.png
This is the json file (derived from the image above) that I'm importing and using to construct the Body
.
{
"cannon_transparent_sm": {
"label": "cannon",
"density": 0.1,
"restitution": 0,
"friction": 0.1,
"frictionAir": 0.01,
"frictionStatic": 0.5,
"fixtures": [
{
"label": "cannon_fixture",
"vertices": [
[ { "x":150, "y":45 }, { "x":134, "y": 0 }, { ":x": 18, ":y":30 }, { "x":1, ""y":56 }, { "x":21, "y":94 }, { "x":86, "y":76 } ],
[ { "x":43, "y":17 }, { "x":44, "y":23 }, { "x":59, "y":19 }, { "x":58, "y":14 } ],
[ { "x":6, "y":41 }, { "x":1, "y":56 }, { "x":18, "y":30 } ],
[ { "x":6, "y":83 }, { "x":21, "y":94 }, { "x":1, "y":56 }, { "x":2, "y":72 } ],
[ { "x":86, "y":76 }, { "x":21, "y":94 }, { "x":25, "y":108 }, { "x":48, "y":124 }, { "x":61, "y":124 }, { "x":73, "y":119 }, { "x":83, "y":109 }, { "x":88, "y":95 } ],
[ { "x":34, "y":118 }, { "x":48, "y":124 }, { "x":25, "y":108 } ]
]
}
]
}
}
The data above was created using the physicseditor tool.
When attempting to add this to my 2D world, there seems to be an issue. I am utilizing the JavaScript library matter-js and fromVertices() to form the sprite.
However, when I implement it, what I witness is different than expected.
https://i.sstatic.net/YJ2Vw.png
To me, it appears as though each group of vertices has been inaccurately positioned with respect to one another.
Here's the JavaScript code I'm using to include the "cannon".
var cannonBodyDef = {
position: Vector.create(300, 50),
density: this._cannon.density,
restitution: this._cannon.restitution,
friction: this._cannon.friction,
frictionStatic: this._cannon.frictionStatic,
frictionAir: 0.9, //this._cannon.frictionAir
};
var cannon = Bodies.fromVertices(300, 200, this._cannon.fixtures[0].vertices, cannonBodyDef);
World.add(engine.world, cannon);
In addition, it falls to the ground (as expected), wobbles slightly, and eventually passes through even though the floor is set to static: true
. Not sure if these issues are related.