- Home /
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?
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.
how do i check how much force is being applied? also don't you need a rigidbody to do physics?
yes sir.. you need to rigidbodify your building objects in order to make them under the rules of physics..
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?
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?
}
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
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Structural Stability 0 Answers
Destroying object when too much force applied? 0 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Can you use keystrokes in a Script? 1 Answer