Aiming a bone to a direction

Hi, im making a third person shooter, and then i got into this problem, where i have no idea on how to make the shoulder/hand bones rotate to face the center of the camera. I tried using the head look controller, but the bones reacted very wierd and has some issues with animations applied. I saw this thread : http://forum.unity3d.com/threads/41951-aim-bone-to-a-direction-%28quick-third-person-aim%29
, and i dont really understand what the answerer meant. I’m still a beginner at scripting, and would anyone help me to explain to me about this problem? I need serious help :frowning:

This is the code from the user “cerebrate” from the thread :

horiRot = HeadLookController.AngleAroundAxis(transform.forward, fireTarget.position - transform.position, transform.up);
vertRot = HeadLookController.AngleAroundAxis(transform.forward, fireTarget.position - transform.position, transform.right);
horiRot = Mathf.Clamp(horiRot, -35, 35);
vertRot = Mathf.Clamp(vertRot, -35, 35);
horiRot = (horiRot /35);
vertRot = (vertRot /35);

aimUp.normalizedTime = -vertRot;
aimDown.normalizedTime = vertRot;
aimRight.normalizedTime = horiRot;
aimLeft.normalizedTime = -horiRot;

THANKS!

Bones have completely arbitrary uncontrollable rotations (not true, but they are nasty to get set up right, at least in my workflow).

Instead of using the bones exported with the character, add new transforms and use those as the bones.

That is -

Add a new object to your scene called “UpperArm” (or whatever). Make your character’s upper arm bone a child of that new object, and make that new object a child of your character’s Shoulder. Then instead of trying to apply rotations to the character’s original arm bone, treat the new UpperArm as the bone. You’ll have complete control over its initial orientation and it should be much easier to calculate rotations.

I used that method and now I can point any bone at any object just by using the “fake” bone’s transform.LookAt( object ). :slight_smile:

1 Like