• 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
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 mac$$anonymous$$nes 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

People who like this

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

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

You shouldn't t$$anonymous$$nk of "rotations" here but in terms of "orientation". They are often used synonymously. However rotations actually represent the change of orientation (an action) w$$anonymous$$le the orientation represents the state. Pipes usually have a "connection axis" w$$anonymous$$ch 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 t$$anonymous$$s 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 w$$anonymous$$ch 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 c$$anonymous$$ld oder of the pipe and it's connector. So usually the connector is a c$$anonymous$$ld 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 t$$anonymous$$s 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
Vonni

People who like this

1 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

How to get Angle float of specific axis.(Turret clamping related). 2 Answers

When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers

How to rotate an object around another 60 degrees with a keypress? 0 Answers

[OAFAT]Why does transform.rotation.x = 45 not work 3 Answers

Quaternion - Euler Angles, weird variable swapping when converting 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