Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by NarallandaKaratoga · Nov 29, 2017 at 01:22 PM · transformmathmatrix

How to get relative transform between two objects?

Say I have objectA and objectB, I want the Transform value between them which may change all of position, rotation and scale. It is something like

new Transform(objectB.transform.matrix * objectA.trasform.matrix.inversed)

does Unity provide this kind of things that will give a simple Transform? If I get the transform matrix, how to apply it to GameObject.transform?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Glurth · Nov 30, 2017 at 11:08 PM

Not all Matrix4x4 results can be represented as a single TRS (translation, rotation, scaling) set. Consider what happens when a rotation operation is applied to an uneven scaling operation: the result is a "shear", which cannot be compensated for using only a single TRS set. This is why a Transform can be converted to a Matrix4x4, but not the reverse.
Possibly useful: There are several useful Unity functions that allow you to specify a Matrix4x4. For example, Graphics.DrawMesh provides a few versions that allow you to specify a Matrix4x4 as input.
Not sure about your situation, but you may be able to achieve the effect as you desire by simply changing the parent of the targetObject. If, for example, it starts as a child of objectB, simply making it a child of the objectA using Transform.SetParent with the worldPositionStays parameter set to false, should have the effect you're looking for. The reason this would work is multiple TRS sets are applied via the new parent-hierarchy (and no-longer applied by the old .parent-hierarchy).

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 Lesliehdez · Feb 16, 2018 at 05:27 PM 0
Share

I need to apply this matrix: "transformation":[15,0,0,0,0,15,0,0,0,0,15,0,0,0,0,1]

and apply it to a gameobject (.obj 3D $$anonymous$$O$$anonymous$$ )to obtain a new transformation. How can i do that? Thank you.

avatar image
-2

Answer by text23d · Nov 30, 2017 at 06:46 PM

not sure why you want matrix. just make GameObject middleGameObject; //and Vector3 middlePos;

and in code (Update function) set :

middlePos = middleTransform.position; middlePos.x = (ObjectA.transform.position.x + ObjectBtransform.position.x)/2; //same for y and z middleGameObject.position = middlePos;

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

97 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

Related Questions

Affine transformations to Object 3 Answers

How to avoid changing transform.parent? 2 Answers

Why is transform.up different than transform.localToWorldMatrix.MultiplyVector(Vector3.up) ? 0 Answers

Is there such a thing as Unity Algebra? 0 Answers

Transform.position of child object not working as intended. 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