Ejemplo n.º 1
0
    float calculateLengthBetweenSkeleton(string BoneName1, string BoneName2, RenderSkinnedComponent renderskinnedcomponent)
    {
        uint boneindex = 0;

        renderskinnedcomponent.FetchBoneIndex(BoneName1, out boneindex);
        Vector3 bone1 = renderskinnedcomponent.GetLocalBoneMatrix((int)boneindex).Translation;

        renderskinnedcomponent.FetchBoneIndex(BoneName2, out boneindex);
        Vector3 bone2  = renderskinnedcomponent.GetLocalBoneMatrix((int)boneindex).Translation;
        Vector3 up     = bone2 - bone1;
        float   length = up.Length();

        return(length);//DivideComponent(Pos, G_Hips.transform.localScale);
    }
Ejemplo n.º 2
0
    Vector3 calculatePosbetweenTwoSkeletonschanges(string BoneName1, string BoneName2, RenderSkinnedComponent renderskinnedcomponent)
    {
        uint boneindex = 0;

        renderskinnedcomponent.FetchBoneIndex(BoneName1, out boneindex);
        Vector3 bone1 = renderskinnedcomponent.GetLocalBoneMatrix((int)boneindex).Translation;

        renderskinnedcomponent.FetchBoneIndex(BoneName2, out boneindex);
        Vector3 bone2  = renderskinnedcomponent.GetLocalBoneMatrix((int)boneindex).Translation;
        Vector3 up     = bone2 - bone1;
        float   length = up.Length();
        //up.Normalize(); // Normalize
        Vector3 Pos = up * 0.5f;

        return(Pos);//DivideComponent(Pos, G_Hips.transform.localScale);
    }
Ejemplo n.º 3
0
    public override void Update()
    {
        Vector3 spinepos = G_BodyParts[(int)BODYPART.SPINE].transform.position;

        if (RagdollEnabled)
        {
        }
        else
        {
            for (int i = 0; i < (int)BODYPART.COUNT; i++)
            {
                G_BodyParts[i].transform.local_world = skin.GetLocalBoneMatrix((int)BoneIndexes[i]);
            }
        }
    }
Ejemplo n.º 4
0
    public override void OnAwake()
    {
        Mass_BodyParts[(int)BODYPART.HIPS]            = 0.15f;
        Mass_BodyParts[(int)BODYPART.SPINE]           = 0.35f;
        Mass_BodyParts[(int)BODYPART.HEAD]            = 0.1f;
        Mass_BodyParts[(int)BODYPART.LEFT_UPPER_ARM]  = 0.03f;
        Mass_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM] = 0.03f;
        Mass_BodyParts[(int)BODYPART.LEFT_LOWER_ARM]  = 0.02f;
        Mass_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM] = 0.02f;
        Mass_BodyParts[(int)BODYPART.LEFT_UPPER_LEG]  = 0.1f;
        Mass_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG] = 0.1f;
        Mass_BodyParts[(int)BODYPART.LEFT_LOWER_LEG]  = 0.05f;
        Mass_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG] = 0.05f;


        string[] BoneNames =
        {
            Hips,         Spine,         Head,
            UpperLeftArm, UpperRightArm, LowerLeftArm,LowerRightArm,
            UpperLeftLeg, UpperRightLeg, LowerLeftLeg,LowerRightLeg
        };



        skin = gameObject.GetComponent <RenderSkinnedComponent>();

        for (int i = 0; i < (int)BODYPART.COUNT; i++)
        {
            BODYPART part = (BODYPART)i;
            G_BodyParts[i] = new GameObject(part.ToString());
            G_BodyParts[i].transform.SetParent(gameObject.transform);
            if (i != (int)BODYPART.SPINE)
            {
                J_BodyParts[i]             = G_BodyParts[i].AddComponent <Joint>();
                J_BodyParts[i].NoCollision = true;
                J_BodyParts[i].Damping     = 0.85f;
            }



            BT_BodyParts[i] = G_BodyParts[i].AddComponent <BoneTransformComponent>();

            BT_BodyParts[i].BoneName       = BoneNames[i];
            BT_BodyParts[i].AnimatedObject = gameObject;
            skin.FetchBoneIndex(BoneNames[i], out BoneIndexes[i]);
            G_BodyParts[i].transform.local_world = skin.GetLocalBoneMatrix((int)BoneIndexes[i]);
        }

        //J_BodyParts[(int)BODYPART.HEAD].Damping = 50.0f;

        Vector3 center;
        //Hips
        SphereCollider hipsCollider = G_BodyParts[(int)BODYPART.HIPS].AddComponent <SphereCollider>();

        hipsCollider.radius             = 0.2f;
        C_BodyParts[(int)BODYPART.HIPS] = hipsCollider;


        //Spine

        BoxCollider spineCollider = G_BodyParts[(int)BODYPART.SPINE].AddComponent <BoxCollider>();

        center                           = calculatePosbetweenTwoSkeletonschanges(Spine, Neck, skin);
        center.x                         = 0;
        center.z                         = 0;
        spineCollider.center             = center;
        spineCollider.size               = new Vector3(center.y, center.y, center.y);
        C_BodyParts[(int)BODYPART.SPINE] = spineCollider;

        //Head
        SphereCollider headCollider = G_BodyParts[(int)BODYPART.HEAD].AddComponent <SphereCollider>();

        headCollider.radius = 0.2f;
        center              = calculatePosbetweenTwoSkeletonschanges(Neck, Head, skin);
        center.x            = 0;
        center.z            = 0;
        headCollider.center = center;


        C_BodyParts[(int)BODYPART.HEAD] = headCollider;

        for (int i = (int)BODYPART.LEFT_UPPER_ARM; i <= (int)BODYPART.RIGHT_LOWER_ARM; i++)
        {
            CapsuleCollider c = G_BodyParts[i].AddComponent <CapsuleCollider>();
            if (PostiveMapping)
            {
                c.rotation = CapsuleCollider.ColliderRotation.RotateY;
            }
            else
            {
                c.rotation = CapsuleCollider.ColliderRotation.RotateX;
            }
            c.radius       = 0.065f;
            C_BodyParts[i] = c;

            J_BodyParts[i].SwingAngle1 = 90;
            J_BodyParts[i].SwingAngle2 = 90;
            J_BodyParts[i].SwingAxis   = Vector3.Zero;
        }

        for (int i = (int)BODYPART.LEFT_UPPER_LEG; i <= (int)BODYPART.RIGHT_LOWER_LEG; i++)
        {
            CapsuleCollider c = G_BodyParts[i].AddComponent <CapsuleCollider>();
            c.radius       = 0.065f;
            C_BodyParts[i] = c;

            J_BodyParts[i].SwingAngle1 = 90;
            J_BodyParts[i].SwingAngle2 = 90;
            J_BodyParts[i].SwingAxis   = Vector3.Zero;
        }

        for (int i = 0; i < (int)BODYPART.COUNT; i++)
        {
            RB_BodyParts[i] = G_BodyParts[i].AddComponent <Rigidbody>();

            RB_BodyParts[i].IsKinematic = AllobjectKinectic;
            //RB_BodyParts[i].Damping = AllobjectDamping;
            //RB_BodyParts[i].AngularDamping = 0.85f;

            RB_BodyParts[i].Friction    = 0.8f;
            RB_BodyParts[i].Mass        = Totalmass * Mass_BodyParts[i];
            RB_BodyParts[i].ActiveState = Rigidbody.ActivationState.Always_Active;
        }

        J_BodyParts[(int)BODYPART.HIPS].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.SPINE];
        J_BodyParts[(int)BODYPART.HEAD].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.SPINE];

        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.LEFT_UPPER_ARM];
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.SPINE];

        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM];
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.SPINE];

        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.LEFT_UPPER_LEG];
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.HIPS];

        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG];
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedRigidbody = RB_BodyParts[(int)BODYPART.HIPS];


        Vector3 ExtraVector = new Vector3(0);



        //Joint from hips to Spine
        J_BodyParts[(int)BODYPART.HIPS].Axis            = new Vector3(0, 0, -90);
        J_BodyParts[(int)BODYPART.HIPS].SwingAxis       = new Vector3(0, 0, -90);
        J_BodyParts[(int)BODYPART.HIPS].NoCollision     = true;
        J_BodyParts[(int)BODYPART.HIPS].SwingAngle1     = 64;
        J_BodyParts[(int)BODYPART.HIPS].SwingAngle2     = 90;
        J_BodyParts[(int)BODYPART.HIPS].ConnectedAnchor = -spineCollider.center;


        //Head



        //Joint from spine to head
        J_BodyParts[(int)BODYPART.HEAD].Axis            = new Vector3(0, 0, 90);
        J_BodyParts[(int)BODYPART.HEAD].SwingAxis       = new Vector3(0, 0, 90);
        J_BodyParts[(int)BODYPART.HEAD].NoCollision     = true;
        J_BodyParts[(int)BODYPART.HEAD].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.HEAD].SwingAngle2     = 90;
        J_BodyParts[(int)BODYPART.HEAD].ConnectedAnchor = headCollider.center + calculatePosbetweenTwoSkeletonschanges(Spine, Neck, skin);
        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.HEAD].SwingAngle1 = 64;
            J_BodyParts[(int)BODYPART.HEAD].SwingAngle2 = 59;

            J_BodyParts[(int)BODYPART.HEAD].NoCollision = true;
            ExtraVector   = -J_BodyParts[(int)BODYPART.HEAD].ConnectedAnchor;
            ExtraVector.x = -ExtraVector.x;
            ExtraVector.y = -ExtraVector.y;
            ExtraVector.z = ExtraVector.z + 0.1f; //* 3;
            J_BodyParts[(int)BODYPART.HEAD].ConnectedAnchor = ExtraVector;
        }

        //left arm

        CapsuleCollider limbCollider;

        limbCollider        = (C_BodyParts[(int)BODYPART.LEFT_UPPER_ARM] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(UpperLeftArm, LowerLeftArm, skin);



        center   = calculatePosbetweenTwoSkeletonschanges(UpperLeftArm, LowerLeftArm, skin);
        center.x = 0;
        center.z = 0;
        float value = calculateLengthBetweenSkeleton(UpperLeftArm, LowerLeftArm, skin);

        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //Joint from leftarm totorso
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].Axis        = new Vector3(-90, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAxis   = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].NoCollision = true;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAngle1 = 90;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAngle2 = 90;
        ExtraVector   = calculatePosbetweenTwoSkeletonschanges(LeftShoulder, UpperLeftArm, skin) + calculatePosbetweenTwoSkeletonschanges(Spine, UpperLeftArm, skin);
        ExtraVector.z = Math.Abs(ExtraVector.z);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedAnchor = ExtraVector;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].Anchor          = -limbCollider.center;
        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].Axis        = new Vector3(0, -2.5f, 45);
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAxis   = new Vector3(0, 2.5f, -45);
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAngle1 = 45;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].SwingAngle2 = 48;
            ExtraVector.x = -ExtraVector.x;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedAnchor = ExtraVector;
        }



        //left under arm
        limbCollider        = (C_BodyParts[(int)BODYPART.LEFT_LOWER_ARM] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(LowerLeftArm, LowerLeftHand, skin);

        center              = -SwapXY(calculatePosbetweenTwoSkeletonschanges(LowerLeftArm, LowerLeftHand, skin));
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value = calculateLengthBetweenSkeleton(LowerLeftArm, LowerLeftHand, skin);
        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //Joint from leftudnerarmtooverarm
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].Axis            = new Vector3(-90, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].SwingAxis       = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].NoCollision     = true;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].SwingAngle2     = 90;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].Anchor          = -limbCollider.center;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].ConnectedAnchor = new Vector3(calculateLengthBetweenSkeleton(UpperLeftArm, LowerLeftArm, skin),
                                                                                (-calculateLengthBetweenSkeleton(LeftShoulder, UpperLeftArm, skin) + calculateLengthBetweenSkeleton(Spine, UpperLeftArm, skin)) * 0.5f, 0);
        if (PostiveMapping)
        {
            ExtraVector   = J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].ConnectedAnchor;
            ExtraVector.x = 0;
            J_BodyParts[(int)BODYPART.LEFT_LOWER_ARM].ConnectedAnchor = ExtraVector;
        }

        //Right arm
        limbCollider        = (C_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(UpperRightArm, LowerRightArm, skin);
        center              = -SwapXY(calculatePosbetweenTwoSkeletonschanges(UpperRightArm, LowerRightArm, skin));
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value               = calculateLengthBetweenSkeleton(UpperRightArm, LowerRightArm, skin);
        center.y            = value * 0.5f;
        limbCollider.center = center;

        //Joint from Rightarm totorso
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].Axis        = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAxis   = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].NoCollision = true;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAngle1 = 90;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAngle2 = 90;
        ExtraVector   = calculatePosbetweenTwoSkeletonschanges(RightShoulder, UpperRightArm, skin) + calculatePosbetweenTwoSkeletonschanges(Spine, UpperRightArm, skin);
        ExtraVector.z = Math.Abs(ExtraVector.z);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedAnchor = ExtraVector;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].Anchor          = -limbCollider.center;
        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].Axis        = new Vector3(0, -2.5f, 135);
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAxis   = new Vector3(0, 13.5f, -135);
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAngle1 = 66;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].SwingAngle2 = 55;
            ExtraVector.y = -ExtraVector.y;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedAnchor = -ExtraVector;
            ExtraVector = -ExtraVector;
        }

        if (PostiveMapping)
        {
            Vector3 Copydatahere = new Vector3();

            Copydatahere = J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedAnchor;

            Copydatahere.z = J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedAnchor.z * 2;
            ExtraVector    = J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedAnchor;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_ARM].ConnectedAnchor = Copydatahere;
            Copydatahere   = J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedAnchor;
            Copydatahere.z = ExtraVector.z * 2;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_ARM].ConnectedAnchor = Copydatahere;
        }



        //RightUnderArm
        limbCollider        = (C_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(LowerRightArm, LowerRightHand, skin);

        center              = -SwapXY(calculatePosbetweenTwoSkeletonschanges(LowerRightArm, LowerRightHand, skin));
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value               = calculateLengthBetweenSkeleton(LowerRightArm, LowerRightHand, skin);
        center.y            = value * 0.5f;
        limbCollider.center = center;

        //Joint from Rightudnerarmtooverarm
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].Axis        = new Vector3(-90, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].SwingAxis   = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].NoCollision = true;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].SwingAngle1 = 90;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].SwingAngle2 = 90;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].Anchor      = -limbCollider.center;
        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].ConnectedAnchor = -new Vector3(0, (-calculateLengthBetweenSkeleton(RightShoulder, UpperRightArm, skin) + calculateLengthBetweenSkeleton(Spine, UpperRightArm, skin)) * -0.5f, 0);
        }
        else
        {
            J_BodyParts[(int)BODYPART.RIGHT_LOWER_ARM].ConnectedAnchor = -new Vector3(calculateLengthBetweenSkeleton(UpperRightArm, LowerRightArm, skin), (-calculateLengthBetweenSkeleton(RightShoulder, UpperRightArm, skin) + calculateLengthBetweenSkeleton(Spine, UpperRightArm, skin)) * 0.5f, 0);
        }

        //RightLeg
        limbCollider        = (C_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(UpperRightLeg, LowerRightLeg, skin);
        limbCollider.radius = 0.065f;

        center              = calculatePosbetweenTwoSkeletonschanges(UpperRightLeg, LowerRightLeg, skin);
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value = calculateLengthBetweenSkeleton(UpperRightLeg, LowerRightLeg, skin);
        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //Joint from RightLegJoint
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].Axis            = new Vector3(0, 0, 90);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].SwingAxis       = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].NoCollision     = true;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].SwingAngle2     = 10;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].TwistAngle      = 60;
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].Anchor          = new Vector3(0, calculateLengthBetweenSkeleton(UpperRightLeg, LowerRightLeg, skin) * 0.5f, 0);
        J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedAnchor = calculatePosbetweenTwoSkeletonschanges(Hips, UpperRightLeg, skin) * 2;

        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].SwingAxis       = new Vector3(0, 0, 180);
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].SwingAngle2     = 5;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].TwistAngle      = 90;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].Axis            = new Vector3(0, 180, 0);
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].Anchor          = -J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].Anchor;
            J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedAnchor = new Vector3(-J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedAnchor.x, J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedAnchor.y, J_BodyParts[(int)BODYPART.RIGHT_UPPER_LEG].ConnectedAnchor.z);
        }

        //RightUnderLeg
        limbCollider        = (C_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(LowerRightLeg, RightFoot, skin);
        limbCollider.radius = 0.065f;

        center              = calculatePosbetweenTwoSkeletonschanges(LowerRightLeg, RightFoot, skin);
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value = calculateLengthBetweenSkeleton(LowerRightLeg, RightFoot, skin);
        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //RightUnderLegJoint
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].Axis            = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].SwingAxis       = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].NoCollision     = true;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].SwingAngle2     = 10;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].TwistAngle      = 53;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].ConnectedAnchor = limbCollider.center;
        J_BodyParts[(int)BODYPART.RIGHT_LOWER_LEG].Anchor          = -limbCollider.center;



        //left leg
        limbCollider        = (C_BodyParts[(int)BODYPART.LEFT_UPPER_LEG] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(UpperLeftLeg, LowerLeftLeg, skin);
        limbCollider.radius = 0.065f;

        center              = calculatePosbetweenTwoSkeletonschanges(UpperLeftLeg, LowerLeftLeg, skin);
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value = calculateLengthBetweenSkeleton(UpperLeftLeg, LowerLeftLeg, skin);
        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //Joint from LeftLegJoint
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Axis            = new Vector3(0, 0, -90);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].SwingAxis       = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].NoCollision     = true;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].SwingAngle2     = 10;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].TwistAngle      = 60;
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Anchor          = new Vector3(0, calculateLengthBetweenSkeleton(UpperLeftLeg, LowerLeftLeg, skin) * 0.5f, 0);
        J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedAnchor = calculatePosbetweenTwoSkeletonschanges(Hips, UpperLeftLeg, skin) * 2;

        if (PostiveMapping)
        {
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].SwingAxis   = new Vector3(0, 0, 180);
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].SwingAngle2 = 5;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].TwistAngle  = 90;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Axis        = new Vector3(0, 180, 0);
            //  J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Axis = new Vector3(0, 0, 0);
            //          J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Swing = new Vector3(0, -90, -225);
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Anchor          = -J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].Anchor;
            J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedAnchor = new Vector3(-J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedAnchor.x, J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedAnchor.y, J_BodyParts[(int)BODYPART.LEFT_UPPER_LEG].ConnectedAnchor.z);
        }


        //LeftUnderLeg
        limbCollider        = (C_BodyParts[(int)BODYPART.LEFT_LOWER_LEG] as CapsuleCollider);
        limbCollider.height = calculateLengthBetweenSkeleton(LowerLeftLeg, LeftFoot, skin);
        limbCollider.radius = 0.065f;

        center              = calculatePosbetweenTwoSkeletonschanges(LowerLeftLeg, LeftFoot, skin);
        center.x            = 0;
        center.z            = 0;
        limbCollider.center = center;
        value = calculateLengthBetweenSkeleton(LowerLeftLeg, LeftFoot, skin);
        if (PostiveMapping)
        {
            center.y = value * 0.5f;
        }
        else
        {
            center.y = -value * 0.5f;
        }
        limbCollider.center = center;

        //leftUnderLegJoint
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].Axis            = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].SwingAxis       = new Vector3(0, 0, 0);
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].NoCollision     = true;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].SwingAngle1     = 90;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].SwingAngle2     = 10;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].TwistAngle      = 53;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].ConnectedAnchor = limbCollider.center;
        J_BodyParts[(int)BODYPART.LEFT_LOWER_LEG].Anchor          = -limbCollider.center;


        ImpactSpine             = G_BodyParts[(int)BODYPART.SPINE].AddComponent <RagdollImpact>();
        ImpactSpine.G_BodyParts = G_BodyParts;
    }