Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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
2
Question by Celdur91 · Aug 20, 2016 at 08:45 PM · coordinatescoordinate-system

Internal coordinates for each object

Hello.

I have a question about coordinates of objects. I know, that I can get object coordinates using gameObject.transform.position. But is there any build-in method or some way to get internal coordinates? I will explain what I mean on simple example.

alt text

So I want to each object in game has its own coordinate system. For example point 0, 0, 0 should be always in the middle of object (or in the left, bottom corner - that doesn't matter) and it doesn't depend on global position of the object. Is there any way to get it?

coordinates-example.png (18.9 kB)
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 DiegoSLTS · Aug 21, 2016 at 03:23 AM

Objects have their own coordinate system already...

They're always at zero in it's own system, and transform's forward, up and right are the x, y and z axis (I'm not sure if that's the proper order).

Any child object will move and rotate when the parent rotates, keeping it's distance and rotation unchanged relative to the parent coordinates. Transform.local* properties are all relative to the parent's space.

Even for unrelated objects you can move between local coordinates using: TransformPoint, TransformDirection, TransformVector (from local to world space),InverseTransformPoint, InverseTransformDirection and InverseTransformVector (from world to local space).

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 Bunny83 · Aug 21, 2016 at 10:12 AM 0
Share

Exactly. This answer already covers everything.

avatar image
0

Answer by rockin · Aug 21, 2016 at 09:10 AM

I'm not sure if this is the correct way of doing it, but you can use mesh filter bounds center to get the offsets like this:

         MeshFilter mf = GetComponent<MeshFilter>();
         foreach (var v in mf.mesh.vertices)
         {
             var internalPosition = v - mf.mesh.bounds.center;
         } 

It might be good enough for your usecase. It will not work properly for SkinnedMeshRenderers. I think the correct way of doing it is to multiply vertex position with the World2Object matrix, but I haven't found a way to do that outside of shaders.

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 DiegoSLTS · Aug 21, 2016 at 03:37 PM 0
Share

I think the correct way of doing it is to multiply vertex position with the World2Object matrix, but I haven't found a way to do that outside of shaders.

Transform.worldToLocal$$anonymous$$atrix, or just use Transform.InverseTransformPoint.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My ingame avatar's worldspace does not coincide with other objects 1 Answer

Lost in translation... and by that I mean coordinate systems 1 Answer

Is there any way to set a Gameobject's transform matrix to be the World Space? 0 Answers

Scene View - Left-Hand XYZ Coordinates 1 Answer

TextMesh Pro characterInfo coordinates 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