Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
2
Question by riccardo.cantoni · Oct 13, 2015 at 11:52 AM · forcechild objectparent-child

child not moving with parent

very basic here: i want to be able to instantiate cubes as childs of my gameObj and move them toghether. this is just testcode: i want to instantiate a cube object and then apply a force to my current object. the cube should follow, right? no, it doesnt. (gravity is off)

public Transform cube; Transform newCube; Rigidbody rb;

 void Start ()
 {
     rb = GetComponent<Rigidbody>();
     newCube = (Transform)Instantiate(cube, transform.position + Vector3.left, transform.rotation);
     newCube.parent = transform;
 }

 void FixedUpdate()
 {
     rb.AddForce(Vector3.forward);
 }
Comment
Add comment · Show 1
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 Munchy2007 · Oct 13, 2015 at 02:42 PM 0
Share

Does your prefab have it's static flag set? As if so this will prevent it's position from updating.

4 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Garazbolg · Oct 13, 2015 at 01:34 PM

I tried your code and it works fine with me.

The Cube you're trying to instantiate does it also have a rigidbody ? because that would make him not follow.

If not what kind of component do you have on your cube ? For my part i only have Collider, MeshRenderer and Mesh Filter and it works fine.

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 riccardo.cantoni · Oct 15, 2015 at 09:36 AM 0
Share

i got rigidbody on both. the child actually moves very slowly due to attrition i guess (is that even a thing?), and if i try to move them manually pausing playmode they move as expected...

avatar image riccardo.cantoni · Oct 15, 2015 at 09:52 AM 0
Share

i removed the rigidbody and it works now, thanks.

i dont really get it, tho. now i cant apply forces to the child, right? would i be able to if i used a fixedjoint ins$$anonymous$$d?

avatar image Garazbolg riccardo.cantoni · Oct 15, 2015 at 10:24 AM 0
Share

The thing is that rigidbody move in World space no matter if they are the child of a moving gameObject.

But fixedjoint should do the trick (didn't used them much).

avatar image
6

Answer by gersonbellodegoes · Dec 02, 2020 at 12:36 AM

You can check "IsKinematic" when they are together, this will make them follow

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 Shin4ko · May 09, 2021 at 06:54 PM 0
Share

Thank you gersonbellodegoes!

avatar image
2

Answer by taimur_azhar · Jan 20, 2018 at 12:44 PM

I got it fixed as I made freeze position constraints checked.

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 dongminghui1313 · Aug 16, 2021 at 08:34 AM

It's an old question but I will just leave the answer here. For me, the child was set to static by accident. Double-check you didn't turn it on.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerStay() Not Detected In Child Class 0 Answers

How to modify child objects with parent script? 1 Answer

How to make throwable child object? 0 Answers

when i make a gameobject child of another gameobject, then it's scale and rotation both changes in a very wierd manner. 0 Answers

Rotate Child with parent, keeping Child axis in the original direction 2 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