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 Visulth · Jun 14, 2015 at 10:09 PM · rotationphysicsvector3hingejoint

How do I determine which Euler Axis of an object will change when the object is rotated?

I have some art assets that are unfortunately not aligned to Unity's normal axis guidelines (e.g. Y = Up, Z = forward, etc).

Within these are doors that rotate with a HingeJoint. They have a Hinge axis of (-1, 0, 0) which causes them to rotate along Unity's Global Up axis, as desired.

However, when the doors rotate, the values that change are in their Y axis (from 0 decreasing to 270) instead of their X axis (aren't they rotating around the X axis if the Hinge axis is the X axis?).

alt text

You can see the hinge faintly near the wall, pointing upwards.

The issue is that these hinge doors are opened using a script that adds force until it detects the door as being at the opened position. It calculates the end position to compare against by adding the hingejoint limit to the resting open position.

e.g.

 if (currentRotation == endRotation) 
      Cease();

where

 currentRotation = transform.localEulerAngles.z 

and

 endRotation = closedRotation + limits;
 //There is code in place to determine whether to add the .min or .max and 
 //to ensure all the euler angles are positive.

The problem is, how do I determine which axis to get the current rotation from? Is there a way to determine which coordinate that will change?

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
0

Answer by AlwaysSunny · Jun 14, 2015 at 10:09 PM

One thing, before I forget, never check for equality in the realm of floating point numbers. Check for approximations.

You're making this more complicated than it should be.

Foremost, you almost always can and should avoid futzing with euler representations of rotation. They're handy for measurement and in certain situations, but until you learn when and where they are handy, they'll get in the way of writing strong, clean code. Instead, leverage the extensions in the Vector3 and Quaternion classes. There are many tricks and techniques that take advantage of some vector math principles that would be quite complicated to address using basic trig or euler representations. Unfortunately these are best learned through firsthand exposure; definitely read over the documentation for both classes (Vector3, Quaternion).

Regarding your specific issue, it's a bit too confusing to convey, both on your end and mine. Frankly it seems downright irresponsible to spend any time working through this problem when the real answer is "bypass it altogether". Bear in mind the concepts of local space versus global space, and always pick the strongest way to represent and work with your data. The point is that your doors shouldn't care about their orientation in global space. You define a hinge joint and say this hinge value is fully-closed, these are fully-open, and write this logic in such a way that the door's orientation or rotation value on a specific axis just doesn't matter.

Best,

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there a 2d joint for a torsion (rotation) spring? 0 Answers

Follow a curve using physics or transform manipulation 2 Answers

How to get rotation relative to the ground normal? 0 Answers

Turning a rigidbody that's in motion 2 Answers

Game Object rotation sometimes doesn't match defined quaternion 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