- Home /

# Quaternion.Angle and 360 degrees

Hi!

I need to receive a angle between rotations of two objects from 0 to 360 degrees. However the function "Quaternion.Angle" produces value from 0 to 180.

```
public GameObject Object1, Object2;
void Update () {
Object1.transform.Rotate (Vector3.up * 10 * Time.deltaTime);
float angle = Quaternion.Angle (Object1.transform.rotation,
Object2.transform.rotation);
Debug.Log (angle);
}
```

Thanks.

Is this essentially a 2-d problem? That is, does the world have a fixed up vector, and is the angle you're looking for relative to that up vector?

**Answer** by mrde
·
Jan 27, 2011 at 12:08 PM

you can fix one time dot product of these two GameObject forward dot product Vector3 up = dot(object1.transform.forward, object2.transform.forward); and ever@ interpolate state compare direction dot with up (in normalize mode), it must be same vector or invert vector, if dot is invert vector that mean (angle = 360 - angle)

```
void Start() {
Vector3 right = object2.transform.TransformDirection(Vector3.right);
Vector3 up = Vector3.dor(object2.transform.TransformDirection(Vector3.forward), right);
}
```

```
```

void Update() {
Object1.transform.Rotate (Vector3.up * 10 * Time.deltaTime);
Vector3 newup = Vector3.dor(object2.transform.TransformDirection(Vector3.forward), object1.transform.TransformDirection(Vector3.forward));
float angle = Quaternion.Angle (Object1.transform.rotation,
Object2.transform.rotation);
if (up.normalized != newup.normalized) {
angle = 360 - angle;
}
}

not tested.

Did you mean TransformDirection()? Also, you don't have to write 'Vector3 right = object2.transform.TransformDirection(Vector3.right);'; you can just write 'Vector3 right = object2.transform.right;'.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

How to Constrain Quaternion Rotations Over Time? 1 Answer

Quaternion.FromToRotation misunderstanding 2 Answers

problems with quaternion rotations 4 Answers

Check if rotation (only on Y axis) of some object toward another is finshed? 0 Answers

Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers