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 Persona · Apr 06, 2011 at 01:08 PM · forcechildrendetach

Add force to child

How do I add force to a group of child objects on a key press and then detach them so they can float freely in the direction they were launched?

The idea is to make something like breakable glass, where each piece of the object is actually held together by an empty and on a push of a button, the pieces have force applied and separate, giving the illusion of breaking apart.

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 Bampf · Apr 06, 2011 at 01:52 PM

You could start with each child object's rigidbody set to is-kinematic. When the parent object moves the children will follow.

Next: just before (or after?) applying the force turn off is-kinematic on all the children. You can un-parent them with one function call: Transform.DetachChildren. (Note: unparenting them is probably optional. According to the "Parenting" section of the Rigidbody docs, non-kinematic children will still react to forces on them. As long as the parent stays still it should work.)

There are various ways to apply the force. The first one to try is probably Rigidbody.ApplyExplosionForce because the same call for each child (same force and position args) will produce a varying effect depending on how far each piece is away from the center of the blast. But if that doesn't produce the desired effect, you could calculate the position and force differently for each child object. (For example, if the blast doesn't emanate outward from a single point, you might want to push the child objects mostly in the same direction, or collapse them inwards.)

Edit: I haven't tested this, but the code to detach the children after applying an explosive force to them centered at the parent's coordinates might look something like this, in a script attached to the parent:

for (var child : Transform in transform) {
  child.rigidbody.AddExplosionForce(5.0, transform.position, 10.0, 2.0);
}
transform.DetachChildren(); // this line may be optional, as long as parent object is stationary
Comment
Add comment · Show 4 · 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 Persona · Apr 07, 2011 at 04:54 PM 0
Share

So apply force to the parent, then separate it, and they would still have the force of the parent?

avatar image Bampf · Apr 07, 2011 at 05:18 PM 0
Share

I think not. A force on the parent will push it (and everything rigidly attached) in one direction. I'm almost certain you will need to apply the force to each of the children's rigidbodies.

avatar image Persona · Apr 11, 2011 at 07:43 PM 0
Share

So apply force if it's no longer parented?

avatar image Bampf · Apr 11, 2011 at 09:39 PM 0
Share

I added an (untested) example to my answer. The numbers in the AddExplosionForce call would have to be tweaked for your needs.

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

No one has followed this question yet.

Related Questions

How to have child object remain after parent is destroyed? 1 Answer

Add Explosion Force to children? 2 Answers

Detach children on button press 1 Answer

transform.DetachChildren() is deactivating my children's scripts after detaching from the parent 1 Answer

Children detach not working 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