# Calculating how much an object rotated

This topic is 2106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm making a stunt game, and when the character jumps I save the Transform.eulerAngles to a variable, and when it lands I calculate the difference.

However, since I'm using Unity, and it always keeps eulerAngles between 0-360, this causes a problem in the calculations. I know I need to calculate the difference and increment every frame, but what do I do when the angle reaches 360, then skips to 0.

Is there an elegant way to calculate the angle difference with this looping from 360 back to 0?

##### Share on other sites

I would save the unit vector direction (the Up direction or Forward direction, your choice just be consistent) when the character jumps, and you probably want to keep track of it every frame, as what if the user does a double back flip (if possible).

And then, shooting from the hip, I'd check the angle every update between the current and previous unit vector directions and keep a running tally of the angle.

Pseudo code that may not work

OnJump()

{

jumpDir = this.transform.Forward

angleSum = 0

}

OnUpdate

{

angleSum +=  Mathf.Acos(Vector3.Dot(jumpDir, this.transform.forward))

jumpdir = this.transform.forward.

}

##### Share on other sites

I would save the unit vector direction (the Up direction or Forward direction, your choice just be consistent) when the character jumps, and you probably want to keep track of it every frame, as what if the user does a double back flip (if possible).

And then, shooting from the hip, I'd check the angle every update between the current and previous unit vector directions and keep a running tally of the angle.

Pseudo code that may not work

OnJump()

{

jumpDir = this.transform.Forward

angleSum = 0

}

OnUpdate

{

angleSum +=  Mathf.Acos(Vector3.Dot(jumpDir, this.transform.forward))

jumpdir = this.transform.forward.

}

I tested this out, but if for instance I rotate the yaw by 90 degrees, the forward and right directions move together.

To solve my problem, I did away with using AngularVelocity for rotating my character and just used the Quaternions with AngleAxis.

##### Share on other sites

Ah, I assumed you were interested in how much one flipped about a certain axis.  (Ie to measure if a bike flip did a 360 or 720 degree flip, and not all angular movement.  Though you could simply check all three (forward, up, right/left)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75