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