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 Autonomous · Jul 22, 2013 at 01:26 AM · instantiateparentchildfollowclone

How can I make a game object follow an instantiated game object?

The main issue I am trying to resolve is that textures are stretching over a sphere a little poorly. I am going to have a plane represent the sphere, turn off the sphere's render and have the plane follow the sphere around without any collision.

Is there a way to make the plane act as a child and follow the instantiated game object around?

Appreciate the help. :)

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

Answer by robertbu · Jul 22, 2013 at 02:10 AM

If you want something like a child, just make it a child. That is set the Transform.parent of the plane to the transform of the sphere. I don't know how your game is constructed, but in the Start() for the sphere you can do something like:

 GameObject go = GameObject.Find("Plane");
 go.transform.parent = transform;

You could also do it the other way around. Have the sphere set its transform to a public variable on a script attached to the plane. The plane script might look like:

 public Transform toFollow = null;
 
 void Update() {
     if (toFollow != null)
         transform.position = toFollow.position;
 }

The parent/child follows position, rotation, and scale. The second solution only follows the position, though it could be augmented to follow other properties.

Comment
Add comment · Show 2 · 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 Autonomous · Jul 25, 2013 at 06:16 PM 0
Share

Robert thank you for explaining how the parent works, it was a bit confusing for me. I have got kind of what I am looking for working based off your answer.

The plane(object type: plane) is not following the ball(sphere). Although the issue I am having is once the ball is destroyed and re-instantiated, the plane is misaligned. Any idea why that is the case when the plane's transform should be adhering to that of the ball/sphere?

 void LaunchBall()
         {
             if (GameStarted == true)
             {
                 if(attachedBall)
                 {                
                     Rigidbody ballRigidbody = attachedBall.rigidbody;
                     ballRigidbody.position = transform.position + new Vector3(0,1f,0);
                     
                     // Set the BallTexture's position to that of the AttachedBalls
                     var ballTextureTransform = ballTexture.transform;
                     ballTextureTransform.parent = attachedBall.transform;
                     
                     if (Input.GetButtonDown("LaunchBall"))
                     {
                         ballRigidbody.is$$anonymous$$inematic = false;
                         ballRigidbody.AddForce(500f * Input.GetAxis ("Horizontal") + 100f,500f,0);
                         attachedBall = null;
                     }
                 }
             }
         }
avatar image robertbu · Jul 25, 2013 at 06:42 PM 0
Share

If you are destroying the object that is the parent and then doing a new Instantiate(), the transform you set as the parent is gone and you must reset the parent to the new object you instantiated. When you say 'misaligned' do you mean the plane is rotate wrong? $$anonymous$$aking something a child does not change its location or rotation. In fact preserves the relative position and rotation between the two at the time the linkage was made. You likely have to reset the rotation around line 9 to the initial rotation of the plane just as you do for the position on line 8.

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

15 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

Related Questions

Make a simple tree 1 Answer

[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer

How to find and remove the last child of parent? 1 Answer

Access the renderer of a clones child object 1 Answer

Prefab, procedural attachment of child, childCount return 0 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