• 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
1
Question by sam32x · Jul 18, 2012 at 11:07 AM · destroyforcebuildingsomething

buildings like in red faction guerilla

i want to have a building made of pieces that are stuck together somehow. i know how to stick pieces together with the hierarchy thing but i want to make it so when a certain amount of force is applied to the object it will detach and fall to the ground or go flying or whatever. can anyone tell me how i could make the pieces detach so i can make destroyable buildings?

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
1

Answer by fafase · Jul 18, 2012 at 11:59 AM

You could parent all of your building pieces with an empty game object. And when the force is applied, unparent them, add a rigidbody component and apply the force.

As they will be independant objects, they will be thrown around and hitting other objects and so on.

Comment
Add comment · Show 5 · 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 sam32x · Jul 19, 2012 at 05:55 AM 0
Share

how do i check how much force is being applied? also don't you need a rigidbody to do physics?

avatar image vanofthedawn12 · Jul 19, 2012 at 05:57 AM 0
Share

yes sir.. you need to rigidbodify your building objects in order to make them under the rules of physics..

avatar image sam32x · Jul 19, 2012 at 06:27 AM 0
Share

what about setting the coordinates of the object at the start and then put a rigidbody on with no gravity or rotation and then every 0.2 seconds it moves back to its original position unless it moved a certain amount and if it did then rotation and gravity get turned on, would that work?

avatar image sam32x · Jul 19, 2012 at 06:39 AM 0
Share

like this

 var startx : float = 0;
 var starty : float = 0;
 var startz : float = 0;
 var breakdistance : float = 0.5;
 var broken = 0;
 
 function Start () {
 startx = transform.x;
 starty = transform.y;
 startz = transform.z;
 Invoke("Loop",0.2);
 }
 
 function Update () {
 if(transform.x >= startx + breakdistance){
 Break();
 }
 if(transform.x <= -startx - breakdistance){
 Break();
 }
 if(transform.y >= starty + breakdistance){
 Break();
 }
 if(transform.y <= -starty - breakdistance){
 Break();
 }
 if(transform.z >= startz + breakdistance){
 Break();
 }
 if(transform.z <= -startz - breakdistance){
 Break();
 }
 }
 
 function Loop () {
 Invoke ("Loop",0.2);
 if(broken == 1){
 transform.x = startx;
 transform.y = starty;
 transform.z = startz;
 }
 }
 
 function Break () {
 broken = 1;
 //rigidbody gravity on
 //rigidbody rotating on
 //what do i put for these?
 }
avatar image sam32x · Jul 19, 2012 at 07:38 AM 0
Share

i got it

 var startx : float = 0;
 var starty : float = 0;
 var startz : float = 0;
 var breakdistance : float = 2.5;
 var broken = 0;
 
 function Start () {
 rigidbody.freezeRotation = true;
 rigidbody.useGravity = false;
 startx = transform.x;
 starty = transform.y;
 startz = transform.z;
 Invoke("Loop",0.5);
 }
 
 function Update () {
 }
 
 function Loop () {
 if(broken == 0){
 Invoke ("Loop",0.5);
 if(transform.x >= startx + breakdistance){
 Break();
 }
 if(transform.x <= -startx - breakdistance){
 Break();
 }
 if(transform.y >= starty + breakdistance){
 Break();
 }
 if(transform.y <= -starty - breakdistance){
 Break();
 }
 if(transform.z >= startz + breakdistance){
 Break();
 }
 if(transform.z <= -startz - breakdistance){
 Break();
 }
 transform.x = startx;
 transform.y = starty;
 transform.z = startz;
 }
 }
 
 function Break () {
 broken = 1;
 rigidbody.useGravity = true;
 rigidbody.freezeRotation = false;
 }

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

7 People are following this question.

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

Related Questions

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Destroying object when too much force applied? 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Structural Stability 0 Answers

How to permanently destroy an instance? 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