• 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 noatom · Jun 13, 2014 at 09:49 AM · movementparent

How to move parent when child moves?

So if I have an empty gameobject as parent, and a sphere as its child, and then I add force to the sphere, the sphere will move, but the parent will stay in the same position.

I tried just doing this in the update method:

transform.parent.position = transform.position;

But when I click play, the sphere and its parent just fly out of the place. How should I handle this?

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 andrew-lukasik · Jun 13, 2014 at 10:18 AM 0
Share

As a rule you don't move parent to child position. Just don't. Notice that children position and rotation is Completely Dependent on it's parent position/rotation so it couldn't happen differently.

Whatever you want to do here just consider is it even necessary. If it still is then share your reasons.

avatar image noatom · Jun 13, 2014 at 10:50 AM 0
Share

well consider if I move the sphere by adding impulses to it. Once the sphere rotates a bit, its axis are not pointing in the right direction anymore.

If I want to move forward, I will have use a parent to know the right way.

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by GrahamReeves · Jun 13, 2014 at 10:10 AM

When you change that parent position, you'll be moving the child. And on the next update, the child has moved more.

child position = parent position + child local offset

so you need to compensate for that, this might be a quick fix

 transform.parent.position = transform.position - transform.localpostiion;
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 bluethunder3991 · Jun 02, 2021 at 09:53 AM 0
Share

https://www.youtube.com/watch?v=NFBEgKd1mSc : This works.

avatar image
2

Answer by andrew-lukasik · Jun 13, 2014 at 02:40 PM

Sir, you probably need something like this:

 void Update () {
     Vector3 inputDir = new Vector3(Input.GetAxis("Horizontal"),0f,Input.GetAxis("Vertical"));
     Quaternion rotateInputDir = Quaternion.Euler(0f,0f,0f);//rotate me <3
     rigidbody.AddForce( rotateInputDir * inputDir * 10f );
 }




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

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

24 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

Related Questions

Why are my GameObjects altering themselves? 0 Answers

Children must not flip with parent. 3 Answers

I can'^t move object in seceted axis 0 Answers

Rigidbody Moveposition not working when Camera follows object? 0 Answers

Make a simple tree 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