I have recently I have been trying to attach a mesh to a bone. For example, in my case, there is a character and a weapon. I have tried using the .attachToBone(bone[], object) function, but it is responding strangely. instead of attaching to the character's hand (bone[10]) it seems to follow it's movements but always be positioned incorrectly. For example, when the character is walking, the weapon is positioned about 2 meters away from the character but moving with him. This is my code so far.
BABYLON.SceneLoader.ImportMesh("", "", "Character.babylon", scene, function(newMeshes, particleSystems, skeletons) {
BABYLON.SceneLoader.ImportMesh("", "", "Weapon.babylon", scene, function(newMeshes, particleSystems, skeletons) {
newMeshes[0].attachToBone(character.skeleton.bones[10],character);
});
});
Is this not working because the weapon's parent is the character? Have I written incorrect code?
Thanks in advance.
Can you make sure that your meshes[0].position is zero? example: https://www.babylonjs-playground.com/#1I8UPB#0