Parenting object changes parent position

Hi forum,

I have 2 meshes, mesh 1 is an imported mesh from blender. For simplicity mesh 2 is a Babylon sphere. If I position the mesh2 on mesh1 absolute position it moves the mesh2 to the correct position (mesh1 absolute position).

But when I move mesh2 to mesh1 absolute position, and then do mesh2.parent = mesh1, the mesh2 is moved to another position. How can I parent a mesh to another but keeping the same position?

Thanks

Hiya R.

Try this for kicks. After moving mesh2 to mesh1 abs-poz, do mesh2.bakeCurrentTransformIntoVertices()

THEN try the parenting… see if mesh2 holds its position. (Wingnut crosses fingers) :smiley:

Hi,

It didn’t work :(, but I think it’s an issue with the reference point of the model. I’ll dig more on this.

Thanks for now

Rafael

Excellent doc about difference between .parent and .setparent(): Use a Parent - Babylon.js Documentation

3 Likes

Thank you, I’ll check it our right away

I really enjoy the 2 different methods for parenting (with or without adjusting the transform). I use the 2 versions a lot in my game. Depending on the situation I use one or the other. E.g. for the exploding TnT wagon I use setParent(null) to get the blown up parts unattached from the wagon plate, before those parts get applied the explosion force. Q

2 Likes