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

Pivot point of multi parts body #679

Closed
crunchyfx opened this issue Oct 17, 2018 · 3 comments
Closed

Pivot point of multi parts body #679

crunchyfx opened this issue Oct 17, 2018 · 3 comments

Comments

@crunchyfx
Copy link

Hi

Love the script!

I'm using this script in a custom application, so I don't use the renderer, but just the simulation. Then applies the data from the simulation to my visual objects.

I have a compound body which is made like this:

var body1 = Bodies.rectangle(-75, 0, 50, 50, properties);
var body2 = Bodies.rectangle(-5, 0, 50, 50, properties);
body = Body.create({parts: [body1, body2]});
Body.setPosition(body, { x: 1000, y: 200 });

It is giving me trouble because it seems to centre the pivot point, which means my visual object will be misplaced.

This works fine:

var body1 = Bodies.rectangle(-35, 0, 50, 50, properties);
var body2 = Bodies.rectangle(35, 0, 50, 50, properties);
body = Body.create({parts: [body1, body2]});
Body.setPosition(body, { x: 1000, y: 200 });

... because the the pivot is in the centre on my visual object. Here is an image to give a better overview:

matterjs_parts_center

Problem is of course that my pivot point isn't in the centre. Is there a solution for this?
Can I set the pivot of the compound body?
Can I somehow move the body1 and body2 inside the compound body, to make it similar to my visual object?

Let me know if I need to clarify.

Any help is greatly appreciated,
Jakob Wagner

@liabru
Copy link
Owner

liabru commented Oct 19, 2018

See my reply to #673 for and explanation and possible solution. If you actually want to move the pivot point (therefore centre of mass) then you should move both body.position and body.positionPrev vectors together (so not moving the vertices). Thinking about it this would probably be useful to add as a function!

@crunchyfx
Copy link
Author

Thank you for replying. Moving the pivot is what I want, I already tried moving both position and prevPosition, but didn't get it to work. I will try it again, and come back with more info if I still can't get the result.

@crunchyfx
Copy link
Author

Got it working now. Using your method. Thanks.

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

2 participants