Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Vonni · Oct 05, 2018 at 08:30 AM · rotationquaternioneuleranglescoordinatesspace

Detecting Opposite Rotations of two Pipes

Hey,

I have two pipes that are connected. I need some way to detect when they are rotating in opposite directions of each other and detach them (the direction they get unscrewed only).

The pipes are handled by machines and their local rotation don't change. They are often linked to different objects, so parent is not too useful.

  1. I need some way to get the rotation of PipeA relative to PipeB and vica versa.

  2. If I use euler angles i need some way to deal with rotation popping from 360 degrees to 0.

I got a few methods working a little bit, but they are inconsistent and I need it to work 100% of the time.

PS: I don't need the full range of unscrewing, I don't care about the pipe threads or it needing to rotate a specific amount to get detached, just if angleDif > 5 degrees then detach().

Any help is greatly appreciated, thanks.

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
Best Answer

Answer by Bunny83 · Oct 05, 2018 at 09:45 AM

You shouldn't think of "rotations" here but in terms of "orientation". They are often used synonymously. However rotations actually represent the change of orientation (an action) while the orientation represents the state. Pipes usually have a "connection axis" which has to be aligned with the connection axis of it's counterpart. The easiest solution is when the pipe is aligned with it's local space axis. That way you can use transform.forward / .right, .up as the direction vector. If you have strange diagonal angles for your pipes you may want to add empty gameobjects at the connection points and orient those properly so transform.forward points along the connection axis.


When you connect two pipes you just have to make sure you align the two connection axis. If your pipes have a direction / opposite connectors (male, female) so they only fit together in one way you may want to use a directed axis. So the connector axis of the incoming connection points "inwards" and the connector axis of the outgoing connection points outwards. In this case the axis have to match exactly.


In any case using connector points (empty gameobjects) is the easiest and most flexible approach. In addition to the connection axis you get a whole coordinate space which also allows you to control the rotation around that axis (if that's possible, round pipes?). To connect two pipes you actually connect the two connector objects of the two pipes. The easiest way is to temporarily swap the parent child oder of the pipe and it's connector. So usually the connector is a child of the pipe. Now just unparent the connector and parent the pipe to the connector. They will preserve orientation and worldspace position. Now you can move and rotate the connector any way you like and the pipe will follow. To connect two pipes you just have to move the connector at the same position and orientation as the connector you want to connect to. If you want to allow any connector to connect to any other (no directed connector) you would need to flip the orientation since in this case the connectors all point outwards (or inwards) so two connected pipes will always have opposite connection axes.


Most rotation or orientation problems can be solved that way. With TransformDirection / TransformPoint and InverseTransformDirection / InverseTransformPoint you can easily get a certain direction vector or point from local space to worldspace or the other way round. When using connector objects you usually use those as reference.


As the question stands the actual setup is not really clear. I can update my answer with a more specific answer if the question is more specific. I've once created a trackmania like game for android where you can build your own track from various track pieces.

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 Vonni · Oct 05, 2018 at 09:57 AM 0
Share

Thanks for the response. I think I finally figured it out. Below was what I was looking for.

 Quaternion rot1 = Quaternion.Inverse(p1.rotation) * p2.rotation;

I cannot use linking as I don't control the objects and need to know their relative orientation at all times.link text

rotationlistenertextversion.txt (1.5 kB)

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

126 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 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 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 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 avatar image avatar image

Related Questions

Clarifying the ambiguities of rotation in Unity 1 Answer

Rotate with raw gyro data. 0 Answers

Set Rotation on Multiple Axis 1 Answer

Constant 3D rotation (torque, angular acceleration, etc) GLOBAL to object in space? 1 Answer

Rotating a character relative to the ground's rotation 1 Answer


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