problem with vector3.Angle with a fixed joint

i need measure angle of a rigidbody conected to a fixed joint, but inside the simulation the results are incorrect. i am using vector3.angle.

i need simulate a pendulum and measure the angle of the pendulum, any help?
i include the project

[24838-new+unity+project±+copia.zip|24838]

this is the code:

using UnityEngine;
using System.Collections;

public class angulo : MonoBehaviour {
public Transform target;
public float anguloMedida;
public enum direccion{x,y,z}
public direccion direccionActual = direccion.x;
Vector3 valor;
void Update() 
{
switch (direccionActual) 
{
case direccion.x:
valor = transform.right;
break;

case direccion.y:
valor = transform.up;
break;
case direccion.z:
valor = transform.forward;
break;
}
Vector3 targetDir = target.position - transform.position;
Vector3 forward = transform.forward;
float anguloMedida = Vector3.Angle(targetDir, valor);
print (anguloMedida);	
}
}

[24837-angle+problem.png|24837]

I don’t understand those numbers, but maybe using transform.forward is the problem?

transform.forward is your personal forward, the blue arrow. It spins as the pivot spins, so they cancel. It’s like driving a car in a circle while checking if the passenger is on your left or behind you.

Seems like there should be one fixed reference, such as comparing to up: Angle(Vector3.up, target.position - transform.position).

Oh my god, its fixed now, you are right, i have to use vector3.up, i copy the code from the script reference they should change this, anyway thanks very much.