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 mdolnik · Aug 20, 2013 at 05:06 PM · rigidbodychilddragparentinggroup

How to move a group of objects with rigidbodies together?

I know this has been discussed many times and is considered to be bad practice.

What I am wanting to do is click and drag multiple objects that already have rigidbodies. These are currently moved by parenting them to an empty game object with rigidbody, that is moved via spring joint to another empty game object moved by transform.

Currently I have:

       [dragging object]  <- Rigidbody (kinematic), moved via transform
               |
               |  <- spring Joint
               |
       [empty parent obj]   <-  Rigidbody (not kinematic / rotation locked) moved via spring joint
         /     |      \
        /      |       \     <- Parenting
       /       |        \
   [child]  [child]   [child]  <- Multiple child Rigidbodies (kinematic)


I want to be able to have all of the children drag in unison and this current setup DOES work, except it doesn't have collisions as a group (ie, if child to the left runs into an immovable wall, the whole group doesn't stop)

I know about the compound collider thing, that if I were to dynamically remove all child rigidbodies that would work the way I want. But many of the child objects (before moving) will have joints, forces, etc that would make frequently removing/adding rigidbodies a pain.

I've tried a few methods using joints instead of parenting, but even with adjusting the spring/joint settings, the objects seem to bounce, spin, etc in a way I don't want.

Is there any good way to move a group of separate objects as a collective without removing the rigidbodies?

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

2 Replies

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

Answer by mdolnik · Aug 20, 2013 at 09:59 PM

Thanks 'whydoidoit'... I ended up going with a method of using ConfigJoints instead of parenting, with the values tweaked... for anyone's future reference this is what I ended up with:

      [Spring Object]  <- Rigidbody (kinematic), moved via transform
               |
               |  <- spring Joint
               |
       [Dragged Obj]   <-  Rigidbody (not kinematic / rotation locked) moved via spring joint
         /     |      \
        /      |       \     <- Config Joint(s) [locked]
       /       |        \
   [child]  [child]   [child]  <- Multiple child Rigidbodies
 
 
 Spring Object: 
          Rigidbody: Mass 1 | Drag 0 | AngDrag 0.05 | Grav false | Kinematic true
          Spring: Spring 40 | Damper 4 | Max Dis 0.01 | BreakForce 10
 
 Dragged Obj:
          Rigidbody: Mass 1 | Drag 15 | AngDrag 1 | Grav false | Kinematic false | FreezeRot XYZ
          Config Joint(s): XYZMotion Locked | ProjectionMode Pos&Rot
 
 Child Objects
          Rigidbody: Mass 1 | Drag 0 | Kinematic False | Grav false

The only thing now is to do a OnJointBreak() check to re-init when the spring pulls too hard on a solid wall/floor and breaks the connection

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
1

Answer by whydoidoit · Aug 20, 2013 at 06:35 PM

A rigidbody specifies a collision group. You don't need rigidbodies on the [child] objects when they are being dragged, their colliders will be a compound group on the parent which should give you the effect you want.

If you sometimes need rigidbody components on the [child] objects then you will have to Destroy and AddComponent them when switching between modes of operation.

Comment
Add comment · Show 8 · 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 mdolnik · Aug 20, 2013 at 06:40 PM 0
Share

I mentioned:

But many of the child objects (before moving) will have joints, forces, etc that would make frequently removing/adding rigidbodies a pain.

This method is the last resort that I want to go to, because that would require keeping track of all of the connections that would get broken when removing the rigidbody.

avatar image whydoidoit · Aug 20, 2013 at 06:47 PM 0
Share

Yep and I'm afraid that's all you've got unless you want to write the code to pass the collisions back up to the parent, perhaps using Send$$anonymous$$essageUpwards.

As I said, if you apply a rigidbody you've created a collision group of that item and anything with a collider and no rigidbody beneath it. If you add a rigidbody to a child collider then it will not be passing its collisions to the parent.

avatar image mdolnik · Aug 20, 2013 at 06:52 PM 0
Share

Darn... Does there happen to be any way to know which connections depend on the individual child rigidbody (ie: constant force, joints, etc), to restore later?

avatar image whydoidoit · Aug 20, 2013 at 06:55 PM 0
Share

But aren't you child objects kinematic (and hence not having much to do with physics apart from collision) in your diagram? Perhaps I'm missing something....

avatar image whydoidoit · Aug 20, 2013 at 06:56 PM 0
Share

If you have to, just create a script on the children that reacts to OnCollisionEnter and sends it upwards or just to the parent - presu$$anonymous$$g that is how you are detecting collision?

Show more comments

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

16 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

Related Questions

Child rigidbody clipping through walls. 2 Answers

Parenting 2 Rigidbodies Is What I'm Trying To Do? 0 Answers

" You should never have a parent and child rigidbody together " ? 2 Answers

Simulate 'Child' Effect by Script 2 Answers

OnCollisionEnter getting child instead 0 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