x


Equiping Weapon to a Character

So I'm animating my character in max and importing to unity. Now I'd like to be able to switch weapons within the code in game and was wondering how I'd go about doing it so that the weapon moves with the animations.

Thoughts.. 1. Attach the weapon to a bone in the skeleton from max. This is a bone just for one handed weapon angles and movements. But this would need the weapon to be part of that bone 100% within unity not sure if I can do that.

  1. Add the weapon to max and have different animations for each type. (yuck)

Help would be appreciated, I'm not a programmer and this is all very new to me. I think I've been doing pretty well though.

Thanks.

more ▼

asked Mar 14 '10 at 02:58 PM

Jason Mathews gravatar image

Jason Mathews
129 6 7 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

In Unity, all bones are just Transforms, so you can attach child objects to any particular bone just as easily as parenting an object to a normal gameObject. This can be done in the editor, or via scripting.

For more information in general about using animated characters in Unity, read this manual page:

Unity - Character Animation

To parent an object to another at runtime using script, it's simply a matter of assigning the transform.parent property to some other object's transform. In your case you'd want to set the weapon object's transform.parent to the hand bone's transform.

You might also want to subsequently set the weapon's localPosition and localRotation to Vector3.zero and Quaternion.identity respectively (depending on how your weapon's pivots are set up).

more ▼

answered Mar 14 '10 at 08:18 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Awesome! Thanks this helps a lot.

Mar 14 '10 at 08:49 PM Jason Mathews

I'm having trouble with this. Once I parent my weapon to the hand bone, the bones seem to "disconnect" from the body and don't get animated anymore (while the deformed mesh does!).

Mar 26 '10 at 02:00 PM Orion 1

I haven't tested fully YET, but I'm adding a specific bone in 3ds Max to represent the sword/gun/bow/etc. This way it doesn't affect the rest of the bones or weighting.

Mar 31 '10 at 03:22 AM Jason Mathews
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1044
x218
x143

asked: Mar 14 '10 at 02:58 PM

Seen: 8355 times

Last Updated: Mar 14 '10 at 02:58 PM