Calculating how much an object rotated

Started by
2 comments, last by ferrous 10 years, 3 months ago

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?

Advertisement

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

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)

This topic is closed to new replies.

Advertisement