BabylonFan Posted November 15, 2015 Share Posted November 15, 2015 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 15, 2015 Share Posted November 15, 2015 hello, just move parent affectation inside the callback:) importMesh is asynchronous (hence the callback) Quote Link to comment Share on other sites More sharing options...
BabylonFan Posted November 15, 2015 Author Share Posted November 15, 2015 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); Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 15, 2015 Share Posted November 15, 2015 Let's assume your monster is a cute rabbit, then this here is what you wanna do, right: http://www.babylonjs-playground.com/#GLYMS Seems to work to me... maybe you can show the problem with the help of the playground. Quote Link to comment Share on other sites More sharing options...
BabylonFan Posted November 15, 2015 Author Share Posted November 15, 2015 I don't understand how you change the position of the box here? I would like something like this, yes, it's hard to show it cause its a whole game Quote Link to comment Share on other sites More sharing options...
fenomas Posted November 16, 2015 Share Posted November 16, 2015 You're setting parent on a material, rather than on the meshes. Fix:for(var i = 0; i < newMeshes1.length; i++) { newMeshes1[i].parent = parentMonster;} Quote Link to comment Share on other sites More sharing options...
dbawel Posted November 16, 2015 Share Posted November 16, 2015 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. Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 16, 2015 Share Posted November 16, 2015 Ah, I just copied from the code in the initial post, didn't even expect that "monster" could be a material Wingnut 1 Quote Link to comment Share on other sites More sharing options...
BabylonFan Posted November 16, 2015 Author Share Posted November 16, 2015 You're setting parent on a material, rather than on the meshes. Fix:for(var i = 0; i < newMeshes1.length; i++) { newMeshes1[i].parent = parentMonster;} I did this but now the model doesn't show on screen.. Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 16, 2015 Share Posted November 16, 2015 New example: http://www.babylonjs-playground.com/#GLYMS#2 If it doesn't work with your code and you don't get any error, maybe you can put your code online so we can check it out. But it should work the same way as this playground. Quote Link to comment Share on other sites More sharing options...
dbawel Posted November 16, 2015 Share Posted November 16, 2015 I just tried Iceman's code with both visibility operations and a simple mouse event to move the character around, and the character of course is still visible. It appears you have the answer from the iceman. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.