Sign in to follow this  

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.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;



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

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.