# Calculate sum over all movements and rotations of object

Hello everybody,

I’d like to do a statistic for my application in which the user can move and rotate an object.
In the end I would like to display how far the object has been moved overall and how much the user has rotated the objects.

For the change in position I have the straight forward approach of always adding the change in the objects position to one Vector3 holding the distance in the 3 axis overall. I do this in the Update() method:

``````if (transform.hasChanged){
overallMovedDist  += vector3.Distance(oldPosition, transform.position);
old.position = transform.position;
transform.hasChanged = false;
}
``````

Now for the rotation I wonder, how one would best approach such a statistic?
For users it would probably be best to display the values in Eulerangles, I suppose. So after doing two full rotations around for instance the x-axis one would get something like (4pi, 0, 0) or (2360, 0,0) as a result:
With the same approach as for the position I first tried to calculate this by always directly comparing the change in eulerangles that I got from the quaternions. However if an object is rotated around one axis too far, you get a jump in the values for the other axis as well as some point. If I am correct, this comes from the fact that Unity uses Quaternions internally and the conversion.
I tried some stuff with Quaternions already which you can see beneath.

``````Quaternion relativeChange = Quaternion.Inverse(oldRotation) * transform.rotation; // get rotation between old and new transform.rotation
overallRotation = overallRotation * relativeChange; //add the two Quaternions
oldRotation = transform.rotation;
Debug.Log(overallRotation.ToEulerAngles());
``````

However when I test this in my code, slowly rotate the object around an axis and watch the Log I always get the same thing printed, which is (0.0, 0.0, 0.0). But obviously this is not correct, as I have rotated the object.

Can anybody assist me with how to approach this correctly? Thank you in advance!

Why don’t you use `Vector3` to store the rotation already at the Euler angles. The algorithm is similar to measuring the coordinate change:

``````Vector3 overallRotation, oldRotation;
void Start()
{
oldRotation = transform.rotation.eulerAngles;
}

void Update()
{
if (oldRotation != transform.rotation.eulerAngles)
{
overallRotation += transform.rotation.eulerAngles - oldRotation;
oldRotation = transform.rotation.eulerAngles;
print(overallRotation);
}
}
``````

The angle size will be between 0 and 360 (because `transform.rotation.eulerAngles` has such borders).