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 gigaloon · Sep 21, 2013 at 06:04 PM · javascriptchildchildrenmove an object

How do I find out where a child is with javascript

I want to make a parent move to an object when space is pressed and I don't know how to do that, please help

Comment
Add comment · Show 2
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 Gjallanhorn · Sep 21, 2013 at 09:00 PM 0
Share

do you want to make a child move to his parent?

avatar image gigaloon · Sep 21, 2013 at 11:55 PM 0
Share

no, I want to make the parent move to it's child

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Sep 22, 2013 at 12:07 AM

Use the transform.position on each one as they are in world coordinates

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
avatar image
0

Answer by robertbu · Sep 22, 2013 at 01:06 AM

I'm unsure what part of this problem you are having trouble with. You can fixup the link to the child in the inspector so that the parent has a reference, or you could use Transform.Find() to find a specific child on a known path, or you can search all the children of a transform for a specific child. After you've found the child, it is a bit tricky to move the parent to the child since moving the parent will also move the child. You could do something like:

 pos = child.position;
 transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * speed);
 child.pos = pos;

This will move the parent to the child over time with an eased movement. You could also avoid the moving child issue by temporarily breaking the parent/child relationship and reestablishing it when the move is complete.link text

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 gigaloon · Sep 22, 2013 at 03:21 PM 0
Share

I actually want the child to move too

avatar image
0

Answer by Gjallanhorn · Sep 22, 2013 at 11:15 AM

To find a child, use the transform.Find() function, then move your child.

 var child = transform.Find("NameOfChild");
 
 transform.Translate(child.transform.position);
Comment
Add comment · Show 3 · 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 robertbu · Sep 22, 2013 at 03:48 PM 0
Share

He wants to move the parent to the child, not the child to the parent.

avatar image Gjallanhorn · Sep 22, 2013 at 07:33 PM 0
Share

This code will move the parent to the child position.

avatar image robertbu · Sep 23, 2013 at 05:28 AM 0
Share

Yes, it will immediately translate to the position, but the child will no longer be there. While what he is asking is open to interpretation, I'm assu$$anonymous$$g he wants the child to be at the same position as the parent at the end of the operation.

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

17 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

Related Questions

Update Parent/ Children From Script? 2 Answers

Create multiple instances of an object 2 Answers

Instantiate object to move with other gameObject 0 Answers

accessing a child 1 Answer

Locking child position 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