View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Calculating how much an object rotated

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1OneEyed  Members

Posted 09 January 2014 - 05:28 PM

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?

### #2ferrous  Members

Posted 09 January 2014 - 08:18 PM

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.

}

### #3OneEyed  Members

Posted 09 January 2014 - 08:26 PM

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.

### #4ferrous  Members

Posted 09 January 2014 - 08:36 PM

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)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.