- 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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

### 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

quaternion.eulerAngles 1:1 angle conversion 1 Answer

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