After working the latest design that involves only spring and fixed joint. I found that design does not have stability because the spring physics always move around and collide with other nodes and it makes the nodes always moving around and never stop. As the result, the design does not show similar behaviour with a rag doll.

Therefore I came with a new design and using the combination of hinge and spring joint. Using this joint help me to gain more stability from the physics. Also I able to add small nodes between the main nodes. These small nodes will provide better flexibility for the ragdoll. More small nodes will increase the number of joints, so the movement of ragdoll will be precise and flexible. The number of small nodes will be determined by the user.

To achieve this function, I build a script to increase the number of small nodes based on user value and determine the position based on the main nodes.

newDestination = new Vector3(0, 0.3F * SetValue.numberOfNodes, 0);
destination.position = origin.position – newDestination;

distance = (origin.position – destination.position) / SetValue.numberOfNodes;

for (int i = 1; i < SetValue.numberOfNodes; i++)
{
Rigidbody cloneNodes = Instantiate(nodes, origin.position – (i * distance), origin.rotation);
cloneNodes.name = origin.name + “nodes” + i;

if (i != 1)
{
GameObject.Find(origin.name + “nodes” + i).AddComponent<HingeJoint>();
GameObject.Find(origin.name + “nodes” + i).GetComponent<HingeJoint>().useSpring = true;
}
}

GameObject.Find(origin.name + “nodes” + 1).AddComponent<HingeJoint>();

for (int j = 1; j < SetValue.numberOfNodes; j++)
{
if (j == 1)
{
rb = GameObject.Find(“Body/” + origin.name).GetComponent<Rigidbody>();
GameObject.Find(origin.name + “nodes” + j).GetComponent<HingeJoint>().connectedBody = rb;

}
else
{
rb = GameObject.Find(origin.name + “nodes” + (j – 1)).GetComponent<Rigidbody>();
GameObject.Find(origin.name + “nodes” + j).GetComponent<HingeJoint>().connectedBody = rb;
}
}

rb = GameObject.Find(origin.name + “nodes” + (SetValue.numberOfNodes – 1)).GetComponent<Rigidbody>();
GameObject.Find(“Body/” + destination.name).GetComponent<SpringJoint>().connectedBody = rb;

This is the result from the code above

(Visited 48 times, 1 visits today)