• 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 arttu94 · Sep 11, 2019 at 07:25 AM · parent-childtranslationrotationstransformsmatrix4x4.trs

Non-hierarchical child-parent transformation

I have two objects, a parent object and a child object, the child object has a list of points that I use with a line renderer to visualize, this points don't follow the parent transforms, they are a list of Vector3. that I asign in run time, think of drawing on a sphere. and I want the drawing to move and rotate along with the spehre. I asign them with a raycast on the spehre.

 for (int i = 0; i < pathPoints.Count; i++)
 {
     Quaternion rotation = transform.parent.transform.rotation;
     Matrix4x4 m = Matrix4x4.TRS(transform.parent.position, rotation, Vector3.one);
     pathPoints[i] = m.GetColumn(3);
 }

This is what I have right now, with this, when I move the spehre (parent) the child object follows normally and the point from the child component follows too but goes to the parent's position. so that's a start, I just need the points to retain their local position and when the parent rotates moving them as if they were regular transform objects parented by hierarchy.

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

Answer by arttu94 · Sep 11, 2019 at 08:56 PM

Found an old similar question and now it works the current code I use is this

     Vector3 startPathPosition;
     
         void Start()
         {
             startPathPosition = pathPoints[0];
     
             startPathPosition = DivideVectors(Quaternion.Inverse(transform.parent.rotation) * (startPathPosition - transform.parent.position), Vector3.one);
         }
     
          Vector3 DivideVectors(Vector3 num, Vector3 den) {
      
              return new Vector3(num.x / den.x, num.y / den.y, num.z / den.z);
      
          }
     
         void Update()
         {
             if (pathPoints.Count > 0)
             {
                 for (int i = 0; i < pathPoints.Count; i++)
                 {
                     Quaternion rotation = transform.parent.transform.rotation;
                     Matrix4x4 m = Matrix4x4.TRS(transform.parent.position, rotation, Vector3.one);
     
                     pathPoints[i] = m.MultiplyPoint3x4(startPathPosition);
                 }
             }
        }

it's hard coded to use the first point of the list I was using for reference to place a cube and see what was going on. but it works fine. scale is set to vector3.one as I don't change the scale of the parent object.

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.

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

108 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

Related Questions

Relative transforms and parenting 1 Answer

Animating a mecanim avatar through code with Quaternions. 0 Answers

How to make the child follow the parent's rotation 0 Answers

Constance Force Rotation not transferring to child object. How to fix? 0 Answers

Positioning problem when using hierarchy 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