Matter-js: How to set relative position for each part of compound

Created on 8 Oct 2018  路  2Comments  路  Source: liabru/matter-js

Hi there. I'm trying to create compound body but can't set position for each part individually.

let partA = Body.Rectangle(0,0,50,50);
let partB = Body.Rectangle(0,50,50,50); // here i want to set relative position
let compound = Body.create({parts:[partA, partB]});

I my case my compound consists lot of primitive figures and after adding them they change their positions and centered to the center of total bounds of compound.

expect to see something line this
image

but I see like this
image

Body.setParts(body, parts, true||false) doesn't change the situation.

Can someone explain please, is it a bug or i'm doing something wrong. Also tried to play with constraints but the result is the same.

Thank you.

improve question

Most helpful comment

This happens because the parts are automatically adjusted to ensure that the parent body's origin body.position is at the centre of mass of all parts. So what you should do is call Body.translate(body, offset) right after creation. I realise this is not so intuitive, so I'll consider whether this can be implemented as an option to setParts that won't break too many things.

All 2 comments

This happens because the parts are automatically adjusted to ensure that the parent body's origin body.position is at the centre of mass of all parts. So what you should do is call Body.translate(body, offset) right after creation. I realise this is not so intuitive, so I'll consider whether this can be implemented as an option to setParts that won't break too many things.

Thank you for reply.
As I understand you mean to call translate for each part after creation, right? Unfortunately doesn't helped.
Can you please demonstrate with this example https://jsfiddle.net/18ytjuom

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maximilianberndt picture maximilianberndt  路  4Comments

Zhaopengyang picture Zhaopengyang  路  3Comments

BlueInt32 picture BlueInt32  路  4Comments

cluber22 picture cluber22  路  3Comments

moe091 picture moe091  路  3Comments