• Advertisement
Sign in to follow this  

Calculating how much an object rotated

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

}

Share this post


Link to post
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 this post


Link to post
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement