Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Noxury · Oct 06, 2015 at 10:01 AM · rotationcarscorescore systemflip

How to check if an object has rotated around itself (360° in x,y,z)

Hey folks,

I am trying to finish my car game with some fancy calculations, so I decided to bring up a stunting-system.

I am guessing that the other flip-directions are structured the same, so here is the code only for the frontflip:

 var rot : Vector3; //<- Declarated at the top of the script
 
 if(transform.eulerAngles.x > rot.x){
         rot.x = transform.eulerAngles.x;
         if(rot.x >= 90 && rot.x < 100 && !rot90){
             rot90 = true;
             score += 900;
         }
         if(rot.x >= 180 && rot.x < 190 && rot90 && !rot180){
             rot180 = true;
             score += 1800;
         }
         if(rot.x >= 270 && rot.x < 280 && rot180 && !rot270){
             rot270 = true;
             score += 2700;
         }
         if(rot.x > 359 && rot270 && !rot360){
             rot360 = true;
             score += 3600;
             rot.x = 0;
             return;
         }
     } else {
         rot90 = false;
         rot180 = false;
         rot270 = false;
         rot360 = false;
         rot.x = 0;
     }

For testing purposes I turned UseGravity off and add a RotateAround x-rotation to simulate.

The eulerAngles are a bit problematic because I realized when the car's rotation has reached 90 it reverses the value from 90 to 270 (decreasing value) and when it has reached 270 it goes again back to 90 (increasing value) although the car physically rotates constantly to positive x.

This does not make sense to me, because then the car would be rotating like a windshield wiper.

Any help is appreciated!

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
1

Answer by Rostam24 · Oct 06, 2015 at 10:11 AM

Maybe the easiest solution would be to check for a 90, 180, 270 and >359 degree rotation (which is a rotation in one direction), as well as a 270, 180, 90 and <1 degree rotation (which is a rotation in the other direction).

So a 360 degree rotation (the first one) would only count if the car first rotated 90, then 180, and then 270 degrees. This way small amounts of rotation in either direction won't result in any points.

Comment
Add comment · Show 3 · 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 Noxury · Oct 06, 2015 at 10:49 AM 0
Share

Thanks for your answer, Rostam24! Yeah, this is a good point to query the rotation like that.

For testing purposes I turned UseGravity off and add a RotateAround x-rotation to simulate.

The eulerAngles are a bit problematic because I realized when the car's rotation has reached 90 it reverses the value from 90 to 270 (decreasing value) and when it has reached 270 it goes again back to 90 (increasing value) although the car physically rotates constantly to positive x.

This does not make sense to me, because then the car would be rotating like a windshield wiper.

avatar image Rostam24 Noxury · Oct 06, 2015 at 11:42 AM 0
Share

Long shot, but what happens when you set gravity and drag to 0 and cause rotation using physics ins$$anonymous$$d?

avatar image Noxury Rostam24 · Oct 08, 2015 at 12:20 PM 0
Share

Again, nothing happens. I have updated the code. :D

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

31 People are following this question.

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

Related Questions

2d detect 360 (backflip) rotation on z axis? 2 Answers

How to check if a car has perform stunt? 0 Answers

Flip over an object (smooth transition) 3 Answers

Don't understand how to use DontDestroyOnLoad. 2 Answers

Storing high score 2 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