# How to rotate bone relative to camera using LookAt

Hi. I’ve been struggling with this for a while now. I want my character’s arms to face the opposite direction of the camera. He’s supposed to aim wherever the camera looks, in third person. Preferably using LookAt(), because I (think) I understand how to use it. The problem though, is that the bones I want to rotate have really messed up axes. Both me and a friend tried to change the orientation of the bones local axes in Blender, but it seems that it is not possible. Here is a picture of how the right upper arm bone’s axes look:

As you can see, the z axes points up, when it should really point out of the arm. The +y axis points where -x should be and -x points where +z should point. When I use LookAt, I naturally get some weird results. If the axes where correct, I believe i would write the script something like this?

``````function LateUpdate () {
direction = Vector3(0,0,1);
direction = cameraTransform.TransformDirection(direction);
transform.LookAt(transform.position+direction);
}
``````

I’m not at a computer where i can test this right now, so please correct me if i’m wrong.
This would take a forward direction and transform it so that it is the camera’s forward, and then apply it to the bone. Right? Well, this doesn’t work, as the axes are messed up. How should I go about making the bone rotate to always face the camera’s forward direction?

If I understand LookAt() correctly, it rotates the object’s z axis to the target specified, and then it rotates the object’s y axis to point in either world up direction, or the up direction specified. Is this correct?

Thank you, but this didn’t really produce what I want (for the arm bone to point in the opposite direction of the camera). I changed the code to this

`direction = Vector3(0,0,1); direction = cameraTransform.TransformDirection(direction); transform.LookAt(transform.position+direction); transform.forward = transform.right;`

And that did make the arm bone face the opposite direction of the camera horizontally, but it always stays the same vertically. However, I then also added this code:
transform.eulerAngles.z = cameraTransform.eulerAngles.x;

Since the bone’s right axis is it’s z axis (which is messed up), that code makes it rotate vertically with the camera. My problem seems to be solved. I wish however, that there was some way to conform these weird axes on the bones to Unity’s z-forward standard.

Put this in a script, and place that script on the object that you want to face in the camera’s direction.

``````void LateUpdate () {
transform.LookAt(transform.position+Camera.main.transform.forward);
}
``````

Try doing the LookAt and then doing

``````  transform.up = transform.forward
``````

Although you may need to control the rotation around the facing axis too (the rotation in localEulerAngles.y) after that