Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ronronmx · Jan 10, 2013 at 10:37 PM · rotationquaternioneulerangles

Keeping track of vehicle rotation?

Hey guys, I'm trying to figure out how to tell when my vehicle does a complete 360 degrees flip. What I need to do is when the player jumps the bike, is store the current rotation, and as the bike rotates backwards or forward, I need to keep track of the rotation and detect when it gets back to the starting rotation stored when the player first started the jump.

I am not quite sure what to use to store the starting rotation. Should I use rigidbody.rotation or trabsform.eulerAngles or maybe transform.up...then I imagine keeping track of the rotation would be something similar to:

 // Starting rotation
 Vector3 startRotation = Vector3.Zero;
 
 if( bikeJustLeftGround == true )
 {
     startRotation = transform.eulerAngles;
     bikeJustLeftGround = false;
 }
 
 // rotation of bike compared to starting rotation
 float currentRotation = Vector3.Dot( transform.up, startRotation );
 
 // And then...
 if( currentRotation == startRotation.z )
 {
     Debug.Log("DID A FLIP!!!");
 }

I can't really get the above code to behave the way I need it to behave. Rotations confuse me and I need some help on this one for sure haha

Thanks for your time guys! Stephane

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Jan 11, 2013 at 07:47 AM

Quaternion.Angle() is one good bet for this problem. Instead of saving the eularAngles do something like:

 Quaternion qInitial = transform.rotation;

Then you can test for the current rotation with:

 Quaternion.Angle(qInitial, transform.rotation);

I don't know how your game works, but you might first have to detect that the vehicle made it past 90 degress first and then give some sort fudge factor (i.e. the flip is successful when the angle is back under 20 degrees).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ronronmx · Jan 11, 2013 at 10:29 PM 0
Share

Hey robertbu, thanks for the example. I ended up using a state machine and detecting when the Dot vector is between a & b and switching states, but I'm gonna try with Quaternion.Angle() as you suggested, might be easier to read and also less code.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Quaternion.LookRotation( ) on y axis only, but keep x axis of transform the same? 2 Answers

Writing a custom LookAt() function 2 Answers

Alternative to Quaternion.LookRotation() ? 2 Answers

How do you smoothly transition/Lerp into a new rotation? 3 Answers

Edited mouselook script rotation clamp not working 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges