LLODGAR
A downloadable game
// Attach to an empty GameObject and call BuildRagdoll() to create a procedural stick ragdoll
public class RagdollBuilder : MonoBehaviour
{
public Material limbMaterial;
public GameObject BuildRagdoll(Vector3 position)
{
GameObject root = new GameObject("Ragdoll");
root.transform.position = position;
// Torso
GameObject torso = CreateLimb("Torso", new Vector3(0, 1.2f, 0), new Vector3(0.3f, 0.6f, 0.3f), root.transform);
Rigidbody torsoRb = torso.AddComponent<Rigidbody>();
torsoRb.mass = 3f;
// Head
GameObject head = CreateLimb("Head", new Vector3(0, 1.9f, 0), new Vector3(0.35f, 0.35f, 0.35f), root.transform);
Rigidbody headRb = head.AddComponent<Rigidbody>();
headRb.mass = 1f;
AddJoint(head, torso, new Vector3(0, -0.35f, 0));
// Limbs (simple symmetric setup)
CreateArm(root.transform, torso, new Vector3(-0.45f, 1.4f, 0), "LeftArm");
CreateArm(root.transform, torso, new Vector3(0.45f, 1.4f, 0), "RightArm");
CreateLeg(root.transform, torso, new Vector3(-0.15f, 0.5f, 0), "LeftLeg");
CreateLeg(root.transform, torso, new Vector3(0.15f, 0.5f, 0), "RightLeg");
// Add collider to torso for pickup
BoxCollider bc = torso.AddComponent<BoxCollider>();
bc.size = new Vector3(0.6f, 0.8f, 0.4f);
return root;
}
GameObject CreateLimb(string name, Vector3 localPos, Vector3 scale, Transform parent)
{
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
go.name = name;
go.transform.SetParent(parent, false);
go.transform.localPosition = localPos;
go.transform.localScale = scale;
if (limbMaterial) go.GetComponent<Renderer>().material = limbMaterial;
return go;
}
void CreateArm(Transform parent, GameObject torso, Vector3 pos, string baseName)
{
GameObject upper = CreateLimb(baseName + "_Upper", pos, new Vector3(0.2f, 0.35f, 0.2f), parent);
upper.AddComponent<Rigidbody>().mass = 0.6f;
AddJoint(upper, torso, new Vector3(pos.x > 0 ? -0.2f : 0.2f, -0.15f, 0));
GameObject lower = CreateLimb(baseName + "_Lower", pos + new Vector3(pos.x > 0 ? 0.25f : -0.25f, -0.4f, 0), new Vector3(0.18f, 0.35f, 0.18f), parent);
lower.AddComponent<Rigidbody>().mass = 0.4f;
AddJoint(lower, upper, new Vector3(pos.x > 0 ? -0.25f : 0.25f, 0.15f, 0));
}
void CreateLeg(Transform parent, GameObject torso, Vector3 pos, string baseName)
{
GameObject upper = CreateLimb(baseName + "_Upper", pos, new Vector3(0.22f, 0.45f, 0.22f), parent);
upper.AddComponent<Rigidbody>().mass = 1.0f;
AddJoint(upper, torso, new Vector3(pos.x > 0 ? -0.05f : 0.05f, 0.25f, 0));
GameObject lower = CreateLimb(baseName + "_Lower", pos + new Vector3(0, -0.7f, 0), new Vector3(0.2f, 0.5f, 0.2f), parent);
lower.AddComponent<Rigidbody>().mass = 0.9f;
AddJoint(lower, upper, new Vector3(0, 0.5f, 0));
}
void AddJoint(GameObject child, GameObject parent, Vector3 anchorOffset)
{
CharacterJoint joint = child.AddComponent<CharacterJoint>();
joint.connectedBody = parent.GetComponent<Rigidbody>();
joint.anchor = child.transform.InverseTransformPoint(child.transform.position + anchorOffset);
SoftJointLimit low = joint.lowTwistLimit;
SoftJointLimit high = joint.highTwistLimit;
low.limit = -60f;
high.limit = 60f;
joint.lowTwistLimit = low;
joint.highTwistLimit = high;
}
}
| Status | Released |
| Author | Slappfeska |
| AI Disclosure | AI Assisted, Code |

Leave a comment
Log in with itch.io to leave a comment.