Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the center of mass / anchor point of a body? #461

Closed
AndreasRef opened this issue Aug 10, 2017 · 3 comments
Closed

How to change the center of mass / anchor point of a body? #461

AndreasRef opened this issue Aug 10, 2017 · 3 comments

Comments

@AndreasRef
Copy link

Hi

I want to be able to rotate a elongated rectangle not relative to its center, but relative to one of its end points.
I have looked at this similar issue:
#149

And it seems like I need to change the centre of mass of the rectangle to be at the pivot point

But how is that done? How do I set the anchor point (or change the center of mass) of a body? I cannot find it anywhere in the documentation.

@liabru
Copy link
Owner

liabru commented Aug 10, 2017

Try this:

body.position.x += offset.x;
body.position.y += offset.y;
body.positionPrev.x += offset.x;
body.positionPrev.y += offset.y;

Where offset is the vector of the new centre, relative to the current body position (centre of mass). Maybe I should add this as a built in function, though I'm not sure if the result will be technically physically correct without a few other property updates (e.g. inertia) but should work fine for now.

@ajay1773
Copy link

@liabru what is the positionPrev here?

@ProgrammingLife
Copy link

Try this:

body.position.x += offset.x;
body.position.y += offset.y;
body.positionPrev.x += offset.x;
body.positionPrev.y += offset.y;

Where offset is the vector of the new centre, relative to the current body position (centre of mass). Maybe I should add this as a built in function, though I'm not sure if the result will be technically physically correct without a few other property updates (e.g. inertia) but should work fine for now.

Looks it doesn't work. Tried here: phaserjs/phaser#6442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants