Angle of bones to read the same as the inspector.

I’m having problems getting the angle to read the same as the inspector. See the two attached pictures. The 2 pictures should show the same angle because they are the same angle, but they show different numbers that don’t mach up to what is in the inspector angle for X. thanks in advance for your help.

public class HelpMe : MonoBehaviour
{
public float angle;
public Transform getTransform;

void Update()
{
    angle = Vector3.Angle(getTransform.position, transform.position);

    Debug.Log(angle);
}

Your code doesn’t make much sense ^^. You use two world positions and calculate the angle between them. You can only calculate the angle between direction vectors. Positions are actually direction vectors, however they all start at the world origin and you would calculate the angle between them.

If you want to read the current local angle of a transform you could can use getTransform.localEulerAngles which gives you the 3 euler angles you see in the inspector.


I tried using getTransform.localEuler!Angles and the rotation are inaccurate see firs pic. The Euler angle goes up then back down to the same number even though the angle changed

Then I tried to get the angle of the lower bone (see the code) but the angle kept changing when I moved the upper bone, even though the lower bone did not change the angle. I thought it was because it was not in local space but as you can see in the pic that did not work or else I’m doing it wrong.
@Bunny83 Thanks for your patience with me and your help.

public Transform getTransform;
public float angle;
public float angleLocal;
public float eulerAngleX;
//public GameObject getRotation1;

//public Transform getTransform2;
//public GameObject getRotation2;
public Vector3 localDirection;
public Vector3 direction;

void Update()
{
    localDirection = getTransform.localPosition - transform.localPosition;
    angleLocal = Vector3.Angle(Vector3.forward, localDirection); // - 90

    direction = getTransform.position - transform.position;
    angle = (Vector3.Angle(Vector3.forward, direction)); //- 88.482552f

    eulerAngleX = transform.localEulerAngles.x;
}