# Rotating Object to Look at Child Object

Hi,

I have 2 objects A and B where B is the child of A. I am working with the character of my game so A is the arm of the character and B is the hand. The first photo below is the current situation and the second photo is what I want.

The function I made seems to be not finding the right rotation for the object. part1 would be object A and part2 would be object B.

``````private void angleBetween(Transform part1, Transform part2) {
float x1 = part1.localPosition.x;
float y1 = part1.localPosition.y;
float z1 = part1.localPosition.z;

float x2 = part2.localPosition.x;
float y2 = part2.localPosition.y;
float z2 = part2.localPosition.z;

float xBetween = Mathf.Tan(x1-x2);
float yBetween = Mathf.Tan(y1-y2);
float zBetween = Mathf.Tan(z1-z2);
}
``````

The current method I’m trying to use is to get the angle between the two objects and rotate the object according to the angle.

I found some other methods such as using Transform.LookAt or using the direction to change the vector of the object. However, I am new to Unity Scripting and am not familiar with these methods.

Thank you

Are you doing procedural animation of joints / bones? That’s not exactly a trivial thing to do.

Generally you would work from the original local rotation of each joint in the T-pose and then every time you need a new rotation, start from that original local rotation, rotate it by the appropriate local rotation modification, and reapply it to the local rotation.

I’m not really sure what the angleBetween method would tell you as it is dependent on the local positions, which have nothing to do with the relative positions and angles or rotations.

Not only that but keep in mind that all the trig functions operate in radians, and all the inverse trig functions return radians, not degrees. The Mathf.Rad2Deg constant and its reverse can convert here, but nothing related to that will be helpful to what is going on above.