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 unity200 · Jan 25, 2012 at 02:13 AM · gameobjectpositiontransform.position

Getting a childs global position.

Hi, I have a model which consists of several meshes eg, walls, doors etc. They are all grouped under one gameobject eg house. I set this gameobject at position(0,0,0). Now the wall at the back of the house is obviously not at position (0,0,0). However I'm not sure how exactly to find this position. I've tried transform.position and transform.localPosition but these just print out the position(0,0,0), which is not what I want. Can anyone please help me?

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

Answer by Lo0NuhtiK · Jan 25, 2012 at 02:46 AM

Should work just fine if you're putting it on the child object(s).
transform.position does give the world coordinates.
If it's not child objects you're talking about, and just other parts of one big object, then you could make empty child objects and position them where you want them to be and then use those coord's.

Put this on a child object and hit "P" to see the debug's in the console. ->

 var myTrans : Transform ;
 var myParent : Transform ;
  
 function Start(){
    myTrans = transform ;
    myParent = transform.root ;
 }
  
 function Update(){
    if(Input.GetKeyDown(KeyCode.P)){
       Debug.Log("My world position = " + myTrans.position) ;
       Debug.Log("My position relative to my parent = " + myTrans.localPosition) ;
       Debug.Log("My parent's world position = " + myParent.position) ;
    }
 }
Comment
Add comment · Show 5 · 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 unity200 · Jan 25, 2012 at 08:29 PM 0
Share

$$anonymous$$aybe my ter$$anonymous$$ology is incorrect. I think you're right when you say it's not a child object and that it is just other parts of one big object.

Since this one big gameobject is huge, it's not practical for me to place empty child objects at every position. Is there any other way I could get the position of a component of the gameobject?

avatar image Lo0NuhtiK · Jan 25, 2012 at 08:47 PM 0
Share

I guess lots of math lol ...
Idk... I use empty game objects for all sorts of stuff. I don't think they cost anything on performance at all, they're... empty ...
You could use vertex positions to find your area's also I suppose.

Can you make a screenshot of your object in your hierarchy so we can make sure it doesn't have children on it and something else isn't happening/wrong/whatever before you start going through all the extra effort?

avatar image unity200 · Jan 27, 2012 at 12:06 AM 0
Share

I'm trying to get the object position fro a raycast and hit so would that be causing the problem? $$anonymous$$aybe there is something extra I have to do in this case.

avatar image Lo0NuhtiK · Jan 27, 2012 at 12:32 AM 0
Share

Only thing I can think would cause that to return only the parent position is if
1) It's all one big object with no children like we wonder already.
-OR-
2) The child object(s) don't have any colliders on them and you're ray is being cast through them and hitting the parent collider.

Idk. Be easier to try and figure out on this side with a hierarchy screenshot to see if it's one object or one with children since you're not sure what it is.

avatar image unity200 · Jan 27, 2012 at 02:36 AM 0
Share

Ok here's the screen shot as requested:

http://imageshack.us/photo/my-images/444/screenshot20120127at322.png/

In this case "rac_basic_sample..." is the model and the "Basic Wall..." are the children of the gameobject (I assume). I would like to get the position of "Basic Wall...." rather than the position of "rac_basic_sample..." (which I have set to 0,0,0).

Also would you happen to know if Unity allows for a wildcard search so that I can somehow find the gameobject with the [117685] identifier? I'm trying to highlight specific objects without having to use their full names.

Also thank you for your help so far.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject change Position after game started 1 Answer

Scrolling Sprite Object 0 Answers

Firing a shell from a tank which rotates 2 Answers

linking the new GUI slider to transform of a game object? 1 Answer

Get position for each Gameobject (in array) ? 0 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