Parenting an Object to a bone or get a similar effect with other methods

I have a player object which has a box in his hands as a placeholder for a weapon. To attach a weapon I set it’s parent to the weaponPlaceholder of the player.

This worked fine for static player object. If, however, it is animated with bones, the weapon does not move along.
So I tried parenting the weapon placeholder to the armBone of the players’ skeleton which works fine in Blender. But apparently, Babylon does support a bone as a parent for an object. Neither by importing from a glb nor by setting the relationship in code.

Did I just do it wrong both times or is this really not supported? How can I reach a similar effect in Babylon?

1 Like

I wish this was supported. I thought it might be, as I haven’t tried this in recent versions.

Anyway, The only work around I can think of currently is to parent your bone to a mesh, and then parent your prop to the same mesh. When you animate the parent mesh, the behavior will be what you’re looking for.

Galen

2 Likes

No worries :slight_smile: We’ve got you covered !
You can attach a mesh to a bone:
https://www.babylonjs-playground.com/#11BH6Z#399 (line #43)

3 Likes

Thanks, it’s working like a charm.

1 Like

Sorry I’m coming into this discussion late, but thanks for the info and the playground example! It took me a while to “get it,” though, because I kept making the mistake of trying to do the parenting-to-bone “on the fly,” after I had moved the rigged model to another position besides (0,0,0). It finally worked correctly for me when I placed both at 0,0,0 and did the attaching right at the start, upon load, just like in the playground example. Just in case anyone else makes the same mistake as me…

1 Like