I have loaded my sprites with custom shapes using the matter physics engine. I would like to place sprites in the “visible” center of the sprite thus I try to change the origin of the base sprites. This unfortunately, separates the collision shape and the real image, as you can see below.
Unfortunately, the example does not work if the shape is given by PhysicsEditor, instead of fromVerts. Browsing through the Phaser codebase, my best current bet is the following class:
I once had a similar issue with my 2d car example.
Here is the snipped I used to fixe it.
// get offset of center of mass
// and set the terrain to its correct position
// https://github.com/liabru/matter-js/issues/211#issuecomment-184804576
let centerOfMass = Matter.Vector.sub(terrainBody.bounds.min, terrainBody.position)
Matter.Body.setPosition(terrainBody, { x: Math.abs(centerOfMass.x) + x, y: Math.abs(centerOfMass.y) + y })
// sprites are positioned at their center of mass
var ground = this.matter.add.sprite(0, 0, 'sheet', 'ground', {shape: shapes.ground});
ground.setPosition(0 + ground.centerOfMass.x, 0 + ground.centerOfMass.y); // position (0,0)
Anyone figured this out with containers? Seems broken if you add sprites to a container and put a collision mesh on a container. There’s simply no way to offset it that I can find.