attachToBone bad position

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 :slight_smile:

Hey ! Sorry for the late reply, here is the playground: Thanks in advance for helping me !

pinging @Cedric :slight_smile:

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:

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.

1 Like

Thank you so much, it works very well !