To build the ragdoll, I need to make two different physics model, the spring physics and bounce physics. The spring physics will work as the bounce and joint of the ragdoll and the bounce physics will use to make the object has effects like bouncing from the ground.
Thanks to unity, it has provided us with spring physics. Using SpringJoint function it will provide us with several variables that will help me to model the spring. The variables are damper, spring, tolerance, MaxDistance, MinDistance.
To create this physic, I used several functions from unity like OnCollision Enter to detect if the nodes have reached the ground and reflect to determine the direction of the nodes.
so the algorithm
void OnCollisionEnter(Collision collision)
void Bounce(Vector3 collisionNormal)
var speed = lastFrameVelocity.magnitude;
var direction = Vector3.Reflect(lastFrameVelocity.normalized, collisionNormal);
rb.velocity = direction * Mathf.Max(speed*0.9f);