- Home /
2D Compound colliders fall through objects.
I'm trying to make a compound collider out of a pre-existing group of objects in the scene. I do this by parenting all the objects with collider2ds on them under another object that has a rigidbody2D component attached to it. This seems to work when I group a bunch of blocks without rigidbodies already attached, but they fall through the ground when I group blocks that already have rigidbodies. Here's the code I'm using to group blocks:
GameObject blockHolder = (GameObject)GameObject.Instantiate(blockHolderPrefab,
blocks.FirstOrDefault().transform.position,
Quaternion.identity);
foreach(GameObject block in blocks)
{
if (block.rigidbody2D != null)
Rigidbody2D.Destroy(block.rigidbody2D);//block.rigidbody2D.isKinematic = true;//.collisionDetectionMode = CollisionDetectionMode2D.None;
Debug.Log("block pos" + block.transform.position);
block.transform.parent = blockHolder.transform;
}
What's confusing me is that the two groups of blocks - those with rigidbodies to start and those without - look exactly the same in the inspector. What am I missing here?
Answer by hubatish · Apr 07, 2015 at 09:41 AM
So I figured out a work-around quite a while ago. Since all of my objects were relatively similar (prefabs of approximately the same object), I was able to simply store their positions and values, delete the old objects, and create new ones in the same positions that did not have rigidbodies on them by default.
Your answer
Follow this Question
Related Questions
Ignore collision in particular situation 3 Answers
Collider not stoping the object second time 1 Answer
Problems with OnCollisionEnter, rigidbodys and compound colliders 2 Answers
How to find speed in certain direction? 1 Answer
What is the minimum you need for collision detection to work? 0 Answers