How to put a weapon in a character's hand?

I’m guessing this should be possible, but I haven’t figured it out yet. I’ve got a skinned character mesh, with an extra bone in each hand representing the object they are holding. Now I just need to attach the object - which is a separate mesh, loaded from a different file - to the skeleton as a child and somehow associate it with that bone.

Any advice / examples on how to make this work? Extra credit if I can use the same object for either left or right hand…

If the model is animated - add an additional bone in the skeleton, ex. bone-rightHand-socket (that way you can align the weapon / held item to characters hand.)

Then, after loading the model and animations, just replace the bone for the weapon model on the fly (it will then follow the transformations of the rest of the skeleton.)

Not sure I understand which bone you mean, or what I should be replacing it with. When you say “replace the bone for the weapon” do you mean the bone that is part of the character?

Right now I have an armature for the character that has an extra bone (weapon.L and weapon.R) for each hand. The weapons themselves don’t have any bones.

This is a hero model from WhyDungeons:

Hand has 4 bones (not meshes, bones in the armature) - shoulder, arm, hand, slot.
In code, the last bone is picked up by id:

As:

const slots = [];

model.traverse((child) => {
  const name = child.name.trim(); // Exported bones don't have dots in their names

  if (name.match(/^bone.*/)) {
    slots[name.split('bone')[0]] = child;
  }
});

// Character picked up a new legendary weapon? Add it to a slot.
if (slots.weapon && character.weaponObject) {
  slots.weapon.add(character.weaponObject);
}
2 Likes