dbawel Posted September 14, 2015 Share Posted September 14, 2015 So, Does anyone have an example where a mesh is connected as a chaild to a bone parent? And if so. I recommentd that everyone checks this out and understands how to use it as it is a very key function essential to many scenes and projects. Thanks for bringing this to light again. As it needs to become a standard function used in many projects and games. DB Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 14, 2015 Share Posted September 14, 2015 You mean this? http://www.babylonjs....com/#11BH6Z#18 Use: sphere.attachToBone(skeleton.bones[34], dude); My question is how I recover the bone by name rather than by index like this: skeleton.bones[34] Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 15, 2015 Share Posted September 15, 2015 I find how. I create a search function of the index by name. var searchBoneByName = function(skeleton, searchBoneName) { var index = 0; for (var i = 0; i < skeleton.bones.length; i++) { if (searchBoneName = skeleton.bones[i].name) { index = i; break; } } return index;};thereby makingsword.attachToBone(skeleton.bones[searchBoneByName(skeleton, "hand_left")], character); gryff 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted September 15, 2015 Share Posted September 15, 2015 dad72: once the mesh is attached how would you control its rotation? You don't want the sword sticking into a character. cheers, gryff Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 15, 2015 Share Posted September 15, 2015 I guess you can move the object :sword.position = sword.rotation = maybe Deltakosh can enlighten us on. Quote Link to comment Share on other sites More sharing options...
gryff Posted September 15, 2015 Share Posted September 15, 2015 Ty dad72 Your code has given me something to play around with. And another thought, do you know if there is an equivalent "detachFromBone" - so a character could change weapons? cheers, gryff Quote Link to comment Share on other sites More sharing options...
Gugis Posted September 15, 2015 Share Posted September 15, 2015 You can set it's parent to nullsword.parent = null; Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 15, 2015 Share Posted September 15, 2015 Yes Gryff. detachFromBone() http://doc.babylonjs.com/classes/2.2-alpha/AbstractMesh#detachfrombone-rarr-void gryff 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted September 15, 2015 Share Posted September 15, 2015 Merci beaucoup dad72 cheers, gryff Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 24, 2015 Share Posted September 24, 2015 Fixed Quote Link to comment Share on other sites More sharing options...
petemac Posted October 21, 2015 Share Posted October 21, 2015 Does it work with moveWithCollisions? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 21, 2015 Share Posted October 21, 2015 What do you mean? Quote Link to comment Share on other sites More sharing options...
petemac Posted October 21, 2015 Share Posted October 21, 2015 I tried attaching swordMesh to mymesh skeleton bone: swordMesh.attachToBone(myMesh.skeleton.bones[7]); then moving myMesh with: forwards = new BABYLON.Vector3(parseFloat((Math.sin(myMesh.rotation.y)) / speedCharacter) * scene.getAnimationRatio(), 0, parseFloat((Math.cos(myMesh.rotation.y)) / speedCharacter) * scene.getAnimationRatio());myMesh.moveWithCollisions(forwards); however the swordMesh does not follow. Also the swordmesh looks like the normals have been flipped around.I can see the inside of the sword. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 21, 2015 Share Posted October 21, 2015 for the normals issue, just set swordMesh.material.scalingDeterminant = -1; for the main question: this should work as you can see here:http://www.babylonjs-playground.com/#11BH6Z#33 Quote Link to comment Share on other sites More sharing options...
petemac Posted October 21, 2015 Share Posted October 21, 2015 Thank you deltakosh! I played around with your scene and indeed it does work with moveWithCollisions I investigated further in my scene and found that I missed the second parameter of swordMesh.attachToBone(myMesh.skeleton.bones[7]);changed it to:swordMesh.attachToBone(myMesh.skeleton.bones[7],myMesh);and it worked! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 21, 2015 Share Posted October 21, 2015 Wonderful 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.