Hey ! I’m a beginner of babylon.js and I have an issue. I’m trying to attach a weapon to the right hand of a character with a bone, the weapon follows the movement but it has a bad position. I can make a playground if necessary. I hope you will help me !
Hello, yes playground would be neat
Hey ! Sorry for the late reply, here is the playground: https://playground.babylonjs.com/#I5MNWX#1. Thanks in advance for helping me !
pinging @Cedric
hi @Katherek
When a mesh is attached to the bone, the bone transform becomes the parent of the child (your weapon). So, your weapon is in the space referenced by your bone. The weapon Z direction will be aligned to your bone Z direction.
2 possibilities: check your bone directions and compare them with the weapon and change the bone direction as needed
Or rotate /translate your weapon so it gets aligned properly with your bone. Your weapon world matrix will become a local matrix to the bone.
Hi, sorry to disturb you again. Thank you for your help but when I translate and rotate the mesh it works fine except when I play an animation that moves the bone.
Just added a SkeletonViewer in case this helps with debugging: https://playground.babylonjs.com/#I5MNWX#2
Also, @Katherek, could you add the animation code to your Playground?
The animations are in the glb file, I made one only to test the movement of the weapon
@Katherek, I haven’t dealt with glb animations in a while. I’m not sure what you named your animations or their respective animation ranges (starting frame to ending frame), so it may help if you added the scene.beginAnimation code in your Playground.
I’m not sure what is wrong with attachToBone
, but because you are using glTF, you can attach the weapon to the node representing the bone which is linked to the bone.
Thank you so much, it works very well !