- Home /

# Euler Angles without values being restricted to 0 - 360

How do I get non clamped 0 - 360 degree euler angles? Yes I am aware that Euler angles are defined this way but I want the correct delta for a stunt system.

.

The problem is, that I am adding the delta angles to a vector and if an eulerangle gets > 359.99.. or below 0 it wraps to the opposite value and it therefore adds or substracts 360. (This vector is information only, no transform rotation is applied to this)

.

The thing is: I want to record the total amount of spinning so if the object makes 2 clockwise rolls (X-Axis) the totalRot should be (720, 0,0), but if it makes a parabolic jump it should be (0,0,0) because the same delta angles are being substracted after the amplitude of the curve (see Figure 1)

.

Keep in mind that I want this on all Axes.

```
IEnumerator CalculateTotalRot(){
Vector3 lastEuler = transform.eulerAngles;
Vector3 totalAngles = Vector3.zero
while (!grounded) {
totalAngles += (transform.eulerAngles - lastEuler); //total += Delta - Works unless object exceeds 0 or 360
lastEuler = transform.eulerAngles;
yield return null;
}
Debug.Log("Total Air Rotation: " + totalAngles );
}
```

Debug to visualise the problem:

**Answer** by Bunny83
·
Aug 13, 2019 at 04:55 PM

Unity internally uses a Quaternion to store the rotation. Quaternions can not represent rotations larger than 180° since that's the same as rotating the other way round with a smaller amount. If you want to record the rotation you get from the physics system, you have to track it manually by accumulating the delta angles over time. Just ensure that the delta angle is always between -180 and 180°. So rotations faster than 180° per frame can't be detected reliably. Though that would be way too fast for most physics similations anyways.

From your question it's not clear if it's a 2d or a 3d game. If possible I would not rely on Unity's eulerAngles since they are calculated backwards from the quaternion and around gimbal lock orientations (euler angles issue) the euler angles will suddenly switch around. It's usually better to calculate the signed angle manually based on a reference system. If the rotation you're interested in is only about a single axis you can directly store the reference direction from the last frame and use Vector3.SignedAngle with the current one. If you rotate around the local x axis, use the objects forward direction and the right axis as normal.

```
Vector3 lastFwd = Vector3.forward;
float totalRotation = 0;
void FixedUpdate()
{
float deltaAngle = Vector3.SignedAngle(lastFwd, transform.forward, transform.right);
lastFwd = transform.forward;
totalRotation += deltaAngle;
}
```

Note due to number precision issues the totalRotation might drift over time. There are several possible solutions. One would be to always reset the totalRotation to 0 while on ground

You can pull the absolute rotation vector from the TransformUtils. Do you know anything about any performance repercussions for doing so. I cant imagine there would be any but always good to get a second opinion.

I don't quite understand what you mean. The orientation of a Transform is stored as Quaternion. The TransformUtils is a **pure editor tool** since the editor handles store the euler angles additionally which can actually exceed 360°. However those are human set values, not calculated angles at runtime. The question clearly was about a game feature, not an editor tool. Therefore the TransformUtil is completely out of the question.

I was looking for a work around I thought that the values were persisted like that but evidently they arent I will remove my answer.

Huh? a downvote? Can the voter please leave a comment what you think is misleading or wrong? I'm happy to improve my answer.

Lol @sacredgeometry your answer is gone I posted a comment to thank you for making an explanation video haha

**Answer** by sacredgeometry
·
Aug 13, 2019 at 06:01 PM

Not graceful but try this.

```
float _theta = 0.0f;
float _speed = 100;
void Update()
{
var x = _theta * _speed;
var rotationCount = Math.Floor(Math.Abs(x) / 360);
var rotation = Quaternion.Euler(0, x, 0);
transform.SetPositionAndRotation(Vector3.zero, rotation);
Debug.Log(rotationCount);
_theta++;
}
```

**Answer** by Pangamini
·
Aug 13, 2019 at 04:51 PM

You can keep and manipulate your angles in a Vector3. It's just 3 floats, nothing is clamping them. Then, you convert them to the rotation (quaternion) when you want to actually apply them to a transform.

However this won't work if your object rotation is changed by another source (eg. rigidbody). Reading eulers from the transform will always be clamped

Think again. Vector, it's just a bunch of floats that you can work with. You can write any value to it, and then you convert it one-way to the rotation. Not the other way (rotation of the transform to eulers and back to your vector). There's nothing overwriting your vector with clamped values, so how can it happen?

If you are the one controlling the values then its fine. That was my answer too. I assumed that was not applicable some how and that the rotation was as a side effect of some other behaviour.

If the later is the case then no. It doesnt work. If the former then yeah, my original post and Pangaminis are fine.

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