How to rotate MatterSprite around a point

Hi everyone.

I would like to rotate my MatterSprite around the point on its edge. So I try like this:

gameState.hero = this.matter.add.sprite(200, 200, 'hero');
gameState.hero.setOrigin(0.5,0);
gameState.hero.angle += 10;

Unfortunately this way physics body ignores my pivot point (see attached image)
hero

Here is working example (image is rotating properly, but I would like this pink rectangle around my image :wink: : https://codepen.io/anon/pen/OqrBrp?editors=1010 (hold left mouse button to rotate)

You have to set the offset of the body manually

gameState.hero = this.matter.add.sprite(200, 200, 'hero');
gameState.hero.setOrigin(0.5,0);
  
let offset= {
  x:0,
  y:-gameState.hero.height/2
}
  
let body = gameState.hero.body;
body.position.x += offset.x;
body.position.y += offset.y;
body.positionPrev.x += offset.x;
body.positionPrev.y += offset.y;
1 Like

Thanks a lot. I don’t know what is this positionPrev, but it works!