Specific Bone Manipulation

Hello everyone :slight_smile:

I’m new to Unity and trying out the free 30 day version.

Is there a function in JavaScript that returns the pantiltroll vector angle of a given bone? Perhaps something like:

boneAngle(entityName, BoneID);

and is there a way to manipulate a particular bone through script?

Thanks in advance everyone. :smile:

Yes, you can manipulate bone rotation with scripts. Once you import a rigged character into unity, the bones appear like any other game object, so there’s no “bone-specific” code to worry about. All you’d need is a script somewhere that has a reference to your bone’s transform component and you could go crazy. Here’s a very simple example…

function LateUpdate () {
    if (Input.GetKeyDown("a")) {
        transform.Rotate(Vector3.up, 10)
    }
}

Dragging this script on to any object (you could test it with a cube) would cause the object to spin 10 degrees around its Y axis every time you hit the A key on your keyboard. This could be applied to a bone just as easily as any object in your scene.

If you’d rather have a script on a different object effect the rotation of some other object (or several objects at once) you should check out this comprehensive page about accessing other game objects through code…

http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

The only thing to bear in mind when manipulating bones via code is that you probably want to put the code in a LateUpdate function as I did in the above example. Unlike Update, LateUpdate is sure to happen AFTER your animation has updated the bones position, assuming you have animation playing.