Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by RLin · Jul 09, 2015 at 08:53 PM · rotationtransformcarracingupside-down

How to check if an object is upside-down?

I am making a racing game, and I need to be able to check if a player or AI car is flipped upside down. I have tried using the vehicle's X and Z euler angles to check, but it is not working very well because the values jump due to the obvious problem of gimbal lock. Does anyone know of a way to check using Quaternions?

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

2 Replies

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

Answer by NoseKills · Jul 09, 2015 at 09:09 PM

Something like

 if (Vector3.Dot(transform.up, Vector3.down) > 0)
     // car's up-vector has a down facing component

The dot product is greater than 0 if the car's roof is pointing even slightly downward and it equals 1 when the cars up-vector points to the same direction as Vector3.down (totally upside down). It's also a very fast calculation.

You could find a value between 0 and 1 that works well for you

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 RLin · Jul 09, 2015 at 09:15 PM 0
Share

Thanks, works without any of the weird effects of my method!

avatar image Noxury · Mar 06, 2016 at 05:11 PM 0
Share

Yeah, but how can one check also if the car is sideways (rotated around Z +-90°; Door touches ground)?

avatar image Eno-Khaon Noxury · Mar 06, 2016 at 06:03 PM 0
Share

If we base that on the usage of dot product, it can be deter$$anonymous$$ed rather inexpensively by using a pair of them:

 // C#
 if($$anonymous$$athf.Abs(Vector3.Dot(transform.up, Vector3.down)) < 0.125f)
 {
     // Car is primarily neither up nor down, within 1/8 of a 90 degree rotation
 
     // Therefore, check whether it's on either side. Otherwise, it's on front/back
     if($$anonymous$$athf.Abs(Vector3.Dot(transform.right, Vector3.down)) > 0.825f)
     {
         // Car is within 1/8 of a 90 degree rotation of either side
     }
 }

Because the dot product of two normalized vectors will also have a length of 1, a generalized angle can be calculated from the result.

Using absolute value, I'm taking an either-or, so I'm looking for a value in which the top/bottom is nearly parallel to the ground.

If so, then I deter$$anonymous$$e whether either side is nearly perpendicular to the ground. If so, the car is lying (basically) on its side.

avatar image
0

Answer by Vardanchik · Sep 26, 2020 at 08:04 AM

Thanks! @NoseKills !!!!!!!

Comment
Add comment · 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

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

25 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

Related Questions

inertiaTensor stopping automatic rotation 1 Answer

transform.Translate moving while upside down? 1 Answer

Find GameObject Position(x,z) and rotation(y) 1 Answer

Random Turning? 1 Answer

transform position y changes when character rotates 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