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 attacker5 · Jul 12, 2013 at 02:20 PM · axisalignspringconstrain

Aligning objects on their relative plane.

Hello, I need to align two objects using script. I have two objects, and I want to "connect" them so that if I rotate one, the other rotates, just as if were a child. The only thing is, I cannot actually parent either on of them, because they are rigidbodys that should perform independently. I essentially want to constrain two of their axis to one another.

I am actually making a shock absorber, so the top and bottom of the shock need to stay inline, but must allow for compression.

I know I can achieve this with the "Object Constraints", but I need it to be relative, not in world space, so if the shock rotates, the parts still work properly.

Hopefully that is understandable. Thank You

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 robertbu · Jul 12, 2013 at 03:03 PM

You are going to have to designate one as the parent and the other as the child. Then you will need to move and rotate the child to match the parent. I don't know what this will do the physics and specifically collision detection. To get them to align, I'd project the position of the child onto the line representing the axis of the parent I was aligning with. The Math3D script has a ProjectPointOnLine() function. Rotation you can handle in one of two ways. First, you can just match the rotation of the two objects. Or if you want to allow the child to spin on the axis, you can use a Quaternion.FromToRotation() rotation to match the axes. So if we use the 'up' vector of the parent for alignment (untested):

 transform.position = ProjectPointOnLine(parentObj.position, parentObj.up, transform.position);
 transform.rotation = parentObj.rotation;

Alternate rotation allowing child to spin on axis:

 transform.rotation = Quaternion.FromToRotation(transform.up, parentObj.up) * transform.rotation;

Comment
Add comment · Show 2 · 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 attacker5 · Jul 13, 2013 at 06:12 AM 0
Share

Thank You, with some ideas from your answer, I got it sorted thanks.

avatar image DSebJ · Sep 01, 2014 at 08:53 AM 0
Share

Thanks! The second line was exactly what I needed to align an object with an artificial gravity source.

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

15 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

Related Questions

Constrain LookAt to Local Axis 2 Answers

Aligning to a specific axis (6 DOF Descent-like movement) 1 Answer

How can I align Axis? 0 Answers

Align an axis to a plane 0 Answers

How can I match/align two objects along 1 axis only? 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