• 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 Reverend-Speed · Sep 26, 2020 at 04:34 AM · rigidbodytransformboxcolliderparent-childmoveposition

Why is my Rigidbody child not moving with it's Rigidbody parent?

I'm sure I've solved this problem before with characters on moving platforms, but nonetheless I'm getting behaviour that's confusing me now.


I have two cubes stacked on top of each other, each with a box collider and rigidbody.


The upper cube is the child of the lower cube. Gravity on both rigidbodies is disabled.


In editor and play mode, moving the parent cube by dragging the transform widget moves the child cube (it inherits the transformation).


However, when I run the following simple test code on the parent (moving it with movePosition), the child cube remains motionless, failing to inherit the transformation of the parent.

 private Rigidbody rb;
 
     public float percent = 0.0f;
     void Awake()
     {
         rb = GetComponent<Rigidbody>();
     }
     void Update()
     {
         percent += Time.deltaTime;
         rb.MovePosition(Vector3.MoveTowards(Vector3.up * 2 + Vector3.left * 4, Vector3.up * 2 + Vector3.right * 4, percent));
     }

As I say, I'm certain I've used something similar for characters and moving platforms before (parenting onCollisionEnter etc.)


What's the obvious thing that I'm missing here? This shouldn't be confusing me like it is...!

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 SlowCircuit · Sep 26, 2020 at 05:20 AM

Rigidbodies do not inherit forces/velocity from parent rigidbodies. They act independently. You could apply the move position to both, but there's always the possibility that the child will hit the parent when trying to do that. You could use FixedJoint to keep them together (might need to unchild it), but it depends on what you're trying to accomplish. FixedJoint would really keep them together, but if you want the child to also be able to move on it's own but move with the parent as well, then you might want to take a look at other joint types and see what works best for what you want.

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 Reverend-Speed · Sep 26, 2020 at 12:57 PM 0
Share

Hi @SlowCircuit ! That seems to contradict the docs, though, no?


Parenting When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.


Not sure FixedJoint is going to help much as I want the child to move horizontally independently of the parent. So odd, though, I could have sworn I had similar behaviour working with a character standing on a moving platform...


Ach, to confess, I thought this would be a straightforward issue and it was getting late, so I just posted and hit the hay. =) I'll do some more research here. Thanks for your time!

avatar image SlowCircuit Reverend-Speed · Sep 26, 2020 at 08:06 PM 0
Share

The doc is confusingly worded. I believe it's saying if you move the parent's transform it will move the child's transform as well, but moving the parent rigidbody will not move the child's rigidbody. You can google "unity parent rigidbody not moving child" and you'll find a lot of people with similar issues to you who also have a rigidbody on the child. For what you describe I'd do my first suggestion. Keep it childed. On the parent, assign the child rigidbody in the inspector. Then when you add forces to the parent, add them to the child too. It should work well for what you're trying to accomplish.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

210 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

Related Questions

How to use MovePosition with a parented rigidbody? 1 Answer

Rigidbody.MovePosition relativeTo parent 0 Answers

RigidBody2D - Ignoring other RigidBodies. 1 Answer

C# always move an object forward and still use physics 1 Answer

Parent object is getting generated why ?? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges