Jump to content

Grouping - parent child relationship


BabylonFan
 Share

Recommended Posts

Hello,

 

I have a problem regarding the parent - child relationship. I have imported a 3d object from blender and I would like to bind it to an invisible mesh (box) so it would move. It doesn't work no matter which way I try it. Here's the code:

 

var monster;

var parentMonster = BABYLON.Mesh.CreateBox("p", 3, scene);
 
            BABYLON.SceneLoader.ImportMesh("", "assets/", "monster1.babylon", scene, function (newMeshes1) {
                monster= new BABYLON.StandardMaterial("assets/", scene);
                monster.diffuseTexture = new BABYLON.Texture("assets/monsterlayer1.bmp", scene);
                monster.diffuseTexture.uScale = 1;
                monster.diffuseTexture.vScale = 1;
 
                for(var i = 0; i < newMeshes1.length; i++) {
                    newMeshes1.isVisible = true;
                    newMeshes1.checkCollisions = true;
                    newMeshes1.scaling = new BABYLON.Vector3(1, 0.3, 1);
                    newMeshes1.position = new BABYLON.Vector3(30, -8, 2);
                    newMeshes1.material = posast;
                } 
            });
            monster.parent = parentMonster;
 
            parentMonster.position = new BABYLON.Vector3(30, -8, 2);
            parentMonster.isVisible = false;
 
Please help, I'm desperate.
Thank you.
Link to comment
Share on other sites

Okay, I did it and now it loads, but it still doesn't move like the parent does.. what do I do now?
I also tried to use the translate function but it also doesn't work, I get a type error: monster.translate is not a function

 

monster.translate(BABYLON.Axis.Z, -0.05, BABYLON.Space.WORLD);

Link to comment
Share on other sites

Fenomas' solution is much cleaner, and he of course does answer you're question.  In addition, I would use:

 

mesh.visibility = 0;

 

instead of:

mesh.isVisible = false;

 

This allows you to manipulate all attributes of a mesh and it's children although the surface of the mesh is not visible. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...