- Home /
Multiple connected body on fixed joint
how can i use multiple body connections fixed joint on a object? So an object can be fixed by the objects that are in his side, and not fall down with the rigidbody, but if all the objects around you be destroyed, he'll fall down. is this possible?
thanks.
Does this have to be done with physics or would you accept a code/faking it answer?
i thought in use phisics, but i can use faking aswell
Can you expand a bit on how you have things set up? Like, do you want the object (that's going to fall) fall through a platform of some sort? Do you want it to play a fall animation? What exactly is holding it up?
Asking 'is it possible' will almost always yield a 'yes', the trick is in the 'how'.
Answer by Bunny83 · Jun 24, 2011 at 12:56 AM
Well, it really depends on what exactly you want to achieve. You can of course use multiple fixed-joints to hold the object at the position but in your case it would be simpler and less loading for the physics system to simulate the effect. Joints are useful if they should break automatically when they exceed their maximum force. Your example sounds like a pure logical problem ;)
From your description i guess you have some objects around another object that is going to fall when all of the surrounding objects are destroyed. I don't care about how you destroy the objects. I just show how you can simulate that the objects "hold" the center object.
I've checked all of your other questions to figure out what language you are using. I didn't found anything so i use C#
// FallWhenAllObjectsDestroyed.cs
using UnityEngine;
using UnityEditor;
[RequireComponent (typeof (Rigidbody))]
class FallWhenAllObjectsDestroyed : MonoBehaviour
{
public GameObject[] Constraints;
void Start()
{
rigidbody.isKinematic = true; // disable physics on this object
}
void Update()
{
bool allDestroyed = true;
foreach (GameObject GO in Constraints)
{
if (GO != null)
{
allDestroyed = false;
break; // If there's still an object alive we're not done yet
}
}
if (allDestroyed)
{
rigidbody.isKinematic = false; // re-enable the physics --> object will fall
Destroy(this); // remove this script because it's no longer useful
}
}
}
Just attach that script to the center object and resize the "Constraints" array to your needs. Assign all objects that "holds" the center object to the array and you're done. When all objects are destroyed the object will start falling.