Move multiple meshes at once

Hello! recently I made a house for testing .babylon files. The problem is is that when I use

BABYLON.SceneLoader.ImportMesh("", "assets/", "Clara_th.babylon", scene, function (newMeshes) {
                
                let house = newMeshes[0];

                house.checkCollisions = true;
                house.position = new BABYLON.Vector3(75, 14, 50);
});

I get collision with my walls, but only 1 of them move. I used boxes to make the walls and floor, all seperate objects, but the don’t move as one. Is there any way to fix this? I tried this:

BABYLON.SceneLoader.ImportMesh("", "assets/", "Clara_th.babylon", scene, function (newMeshes) {
                
                let house = newMeshes[0,1,2,3,4,5];

                house.checkCollisions = true;
                house.position = new BABYLON.Vector3(75, 14, 50);
});

But that didn’t work.

My site is here: http://giv0.gitlab.io/fpoy

The terrain is for testing purposes.
The building that is already on the terrain is a combined mesh.

Thanks for any help!

Givo

Hi @Givo
Could you please make a playground ? :slight_smile:

Something like that should work:

BABYLON.SceneLoader.ImportMesh("", "assets/", "Clara_th.babylon", scene, function (newMeshes) {
                
      for (var index = 0; index < newMeshes.length; index++) {
                let house = newMeshes[index];

                house.checkCollisions = true;
                house.position = new BABYLON.Vector3(75, 14, 50);
     }
});
1 Like

@Givo

I hope you follow @Deltakosh’s response, as you need to know how to correctly assign an array or element(s) of an array correctly. You’ll be manipulating arrays constantly if you continue to code.

Cheers,

Galen

The immediate problem will be that all meshes will be moved to the same position :slight_smile:
i suggest parenting to a transformNode or empty mesh, then move that parent.

1 Like

how do I make a parent?

something like that:

BABYLON.SceneLoader.ImportMesh("", "assets/", "Clara_th.babylon", scene, function (newMeshes) {
      let parent = new BABYLON.TransformNode();
      parent .position = new BABYLON.Vector3(75, 14, 50);

      for (var index = 0; index < newMeshes.length; index++) {
                let house = newMeshes[index];

                house.checkCollisions = true;

               house.parent = parent;
     }
});

ill try that sometime.

thanks for the help!

1 Like