Sign in to follow this  
3ddy

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

 

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

Share this post


Link to post
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: 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.