Jump to content

move p2 collision box (anchor)


Recommended Posts

Hey, I'm using p2 physics and I have a sprite (pixel line) that is rotating around some point (beginning of the line). For rotation I use angularVelocity. To display my sprite correctly I had to set it's anchor to (0,1) and it works fine, but collision box remained where it was before. Please check out my code and attached image


		this.obstacle1CollisionGroup = this.game.physics.p2.createCollisionGroup();
		this.obstacle = game.add.sprite(700, 400, "line");
		this.physics.p2.enable(this.obstacle, true);
		this.obstacle.body.angularVelocity = 0.3;
		this.obstacle.body.angularDamping = 0;



Link to comment
Share on other sites

I have tried using for example body.offset but nothing seems to work - am I missing something, or I should rotate my object some other way?

It needs to rotate around that black dot (beginning of line). The sprite of the line is the size of that rectangle

SOLVED after more digging: 


Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...