- Home /
How to make parts of a 2D ragdoll not collide with eachother?
Hello all, I've tried creating a 2D ragdoll and it worked out great... except for one problem. Collision seems to be enabled between the different parts of the body. So for example I don't want leg 1 and leg 2 to collide with eachother how would I do that? Is there a specific thing I need to do in order to mark certain colliders as not collidable with eachother is is there something else I'm missing?
The ragdoll is created like a stick figure, feet are connected to legs which are connected to torso/body. Hands are connected to Arms which are connected to the torso/body. Head connected to torso/body.
Obviously I set the anchor/connected anchor at different points in order to make the rotation around that point. A side question is how would I make the anchor movable? I disabled the "auto configure connected anchor" and was able to move it freely to attach it how I want but the Anchor itself cannot be moved and is stuck in the middle unless I manually type in the X and Y values so that was a little annoying.
Appreciate any help! Thanks in advance.
Please break up multiple parts of a problem into simple individual questions:
Answer by pako · Oct 29, 2017 at 01:55 PM
You must first create a new Layer and assign it to the 2D ragdoll, including all its children:
https://docs.unity3d.com/Manual/class-TagManager.html
e.g. add a layer named "Ragdoll"
Then go to the Physics2D Settings and in the "Layer Collision Matrix" (at the bottom of the Settings), uncheck the layers that you don't want the Ragdoll layer to interact with. e.g. Ragdoll layer should not interact with Ragdoll layer:
Answer by dCalle · Oct 29, 2017 at 12:55 PM
well you could use this in OnEnable()
https://docs.unity3d.com/ScriptReference/Physics2D.IgnoreCollision.html
public Collider2D[] colliders;
void OnEnable()
{
IgnoreCollision(colliders);
}
/// <summary>
/// Ignore Collision between all given Collider2Ds
/// </summary>
public void IgnoreCollision(Collider2D[] colliders)
{
// < length -1 because the last doesn't need to ignore itself ;-)
for (int i = 0; i < colliders.Length - 1; i++)
{
Collider2D firstCollider = colliders[i];
// loop through all colliders firstCollider has to ignore
for (int j = i + 1; j < colliders.Length; j++) {
Collider2D secondCollider = colliders[j];
Physics2D.IgnoreCollision(firstCollider, secondCollider);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612142103im_/https://answers.unity.com/themes/thub/images/avi.jpg)