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 /
  • Help Room /
avatar image
0
Question by Martines_01 · Apr 15, 2020 at 01:53 PM · transformparentchild

GameObject "child" don't follow "parent".

Simple Ping Pong 2D, I want my ball to stay with platform as long as player won't shoot it and start the game. The problem is when I parent my ballPrefab.transform to empty gameObject which is parented already to platform and have transformation where i want to be it's just don't follow.

 public class SpawnBall : MonoBehaviour
 {
     public Transform ballPointRight;
     public Transform ballPointLeft;
 
     private Transform ballPointPosition;
 
     public GameObject ballPrefab;
 
     public static GameObject cloneBall;
 
     public static bool canWeSpawn = true;
 
 
 
     // Update is called once per frame
     void Update()
     {
         if(canWeSpawn == true)
         {
             if (Ball.addPointRight == true)
             {
                 ballPointPosition = ballPointRight;
                 Ball.addPointRight = false;
             }
             else
             {
                 ballPointPosition = ballPointLeft;                
             }
 
             cloneBall = Instantiate(ballPrefab, ballPointPosition.position, ballPointRight.rotation) as GameObject;
             cloneBall.transform.parent = ballPointPosition;
             canWeSpawn = false;
         }
     }
 }

If someone wins ball spawns on left or right platform, we instantiate ball and then parent it to ballPointPosition where it should be. In unity everything is good the cloneBall (Clone) is parent to ballPointPosition but it's dont follow the platform also ballPointPosition don't follow it they stay together at same position. When i drag them through the scene everything works fine.

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
2
Best Answer

Answer by streeetwalker · Apr 15, 2020 at 02:06 PM

@Martines_01, nothing wrong with the code you show, but the question is how are you moving the parent object, and whether or not the physics engine is involved. If the child has a Rigidbody then that is an issue.

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 Martines_01 · Apr 15, 2020 at 02:16 PM 0
Share

That's the player movement code for two platforms : public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour {

     public CharacterController2D controller_01;
     public CharacterController2D controller_02;
 
     float vertical$$anonymous$$ove_01 = 0f;
     float vertical$$anonymous$$ove_02 = 0f;
 
     public float runSpeed = 40f;
 
     // Update is called once per frame
     void Update()
     {
        vertical$$anonymous$$ove_01 = Input.GetAxisRaw("Vertical_01") * runSpeed;
         vertical$$anonymous$$ove_02 = Input.GetAxisRaw("Vertical_02") * runSpeed;
     }
 
     private void FixedUpdate()
     {
         controller_01.$$anonymous$$ove(vertical$$anonymous$$ove_01 * Time.fixedDeltaTime, false, false);
         controller_02.$$anonymous$$ove(vertical$$anonymous$$ove_02 * Time.fixedDeltaTime, false, false);
     }
 }
 

And the ball have rigidbody and walls but the object that is for positioning is an empty object. Also if there is the way to do it withou rigidbody becouse sometimes ball i speeding up or slowing the platforms I don't know how to make this "withous mass" effect that velocity will be always same for the ball and it won't interact with platforms

avatar image streeetwalker Martines_01 · Apr 15, 2020 at 02:23 PM 0
Share

If the child has a Rigidbody, then is under physical forces and it won't move with the parent - it doesn't matter what the parent is. The physics engine is taking over control of the child.

Remove the physics from the child and place it on the parent, and apply the forces to the parent.

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

233 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 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 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

Set parent of an object when they collide? 2 Answers

how add child to multi gameobject 0 Answers

Child transform same as parents transform 1 Answer

How can i add a child to a parrent without changing the transfom of the child ? 0 Answers

Why does disabling an object eliminate its transform performance cost? 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