Parent child transform

Hello there,

have a question regarding parent child transform,

is there a simple and smart way of updating the first objects position , while the second object position is changed with transform control?


  let mainParent = new THREE.Group();
  mainParent.position.x = 0;
  mainParent.position.y = 4;
  mainParent.position.z = -10;

  mainParent.add(ObjectOne);
  scene.add(mainParent);
  ObjectOne.position.z = 10.5; // set at some position and is the child of mainParent,
  ObjectOne.position.y = -10;  // when mainParent move rotates ObjectOne moves and rotates as well
  ObjectOne.position.x = -10.5; // ObjectOne position can be controlled on its own as well 
  
  so far good has the parent child relationship,

// second object

  ObjectTwo.position.z = -20.5; // set at some position
  ObjectTwo.position.y = 2;
  ObjectTwo.position.x = -4;

Thanks

Here is how you can copy the world transforms of an object inside a parent to another object : https://jsfiddle.net/felixmariotto/dyfszha5/6/

Hope it helps

Hi Felix,

sorry did not explain this properly, and got typo in the earlier question,

i am using transform control, and i have the parent group as described above,
and 2 objects,

the first object is parented to the group,

and the second object is not parented to anything,

i would like to change the position of the First object, when the second objects position is changed with
transform controls, ( like FirstObject is parented to the second object )

Thanks

The method in my fiddle can still be used to copy the world transforms of the object controlled by TransformControls, the only difference is you don’t need to do it every frame but only when TransformControls fires a change event.

dosent seem to work, i know i am doing something daft,
as you your method should work ,
another thing to mention is both the object one and object two are attached to transform control

yep it works,
as i said i was being daft,
listening to change event as you had suggested , made this work,

transformControls.addEventListener('dragging-changed', function (event) {

    objectOne.applyMatrix4( objectTwo.matrixWorld );

    });

thanks Felix

1 Like