x


Attaching an object to a bone?

Hi. I am entirely new to Unity and last night I mucked around following a tutorial to set up a simple 3rd person shooter (I mean REALLY SIMPLE), no animations or textures. Just a cube that shoots balls and moves around.

I can see a lot of potential for Unity so I just wanted to check if it can do something and how easy it is... I know how to import a 3d model from Blender so thats all ok.

Question: I just wanted to know what sort of code would be used to attach an object to the bone of another object. Thanks :)

more ▼

asked Apr 09 '10 at 10:15 AM

Sydan gravatar image

Sydan
241 13 14 19

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

3 answers: sort voted first

On Unity bones are just GameObjects with Transform components on, just like any other GameObject. So you attach one GameObject to a bone by making the bone Transform the parent of the GameObject you want attached.

myGameObject.transform.parent = myBone.transform;

To control the relative alignment of the attached GameObject relative to the bone, you can set the localPosition and localRotation of the Transform of the attached GameObject.

more ▼

answered Apr 09 '10 at 10:33 AM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

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

Hi,

I tried this and it works fine, all i did is make 2 vars, 2 Game-Objects,and you can assign the hand and the sword in inspector. But the problem is the sword needs to have the same position or transform as hand, and than i found this :)

http://answers.unity3d.com/questions/51929/attach-object-to-bone-ingame.html

more ▼

answered Apr 03 at 10:59 AM

Erman gravatar image

Erman
1 1

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

I'm trying this too

function Update () {

Sword_500Knight.transform.parent = Hand_R.transform;
}

but I get: unknown identifier for both Hand_R (the bone of player model which script is on) and Sword_500Knight (the prefab sword)

more ▼

answered Dec 16 '10 at 02:20 AM

Jay_Adams gravatar image

Jay_Adams
67 3 3 8

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

x143
x80
x34

asked: Apr 09 '10 at 10:15 AM

Seen: 6116 times

Last Updated: Apr 03 at 10:59 AM