Jump to content

move p2 collision box (anchor)


3ddy
 Share

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

 

game.physics.startSystem(Phaser.Physics.P2JS);
		game.physics.p2.setImpactEvents(true);
		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.setCollisionGroup(this.obstacle1CollisionGroup);
		this.obstacle.anchor.setTo(0,1)
		this.obstacle.body.angularVelocity = 0.3;
		this.obstacle.body.angularDamping = 0;

 

problem.jpg

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

EDIT:
SOLVED after more digging: 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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