Beispiel #1
0
    void Start()
    {
        HumanoidSetUp setUp = this.GetComponentInParent <HumanoidSetUp>();

        slaveController = setUp.slaveController;
        layerMask       = setUp.dontLooseStrengthLayerMask;
    }
    // Start is called before the first frame update
    void Start()
    {
        HumanoidSetUp setUp = this.GetComponentInParent <HumanoidSetUp>();

        characterCamera = setUp.characterCamera;
        masterRoot      = setUp.masterRoot;
        slaveRoot       = setUp.slaveRoot;
        anim            = setUp.anim;
    }
    // Start is called before the first frame update.
    void Start()
    {
        HumanoidSetUp setUp = this.GetComponentInParent <HumanoidSetUp>();

        animFollow = setUp.animFollow;

        maxForceCoefficient       = animFollow.forceCoefficient;
        maxTorqueCoefficient      = animFollow.torqueCoefficient;
        currentNumberOfCollisions = 0;
        currentDeadStep           = deadTime;
        currentStrength           = 1.0f;
    }
    private bool[] limbProfile = { true, true, true, true, true, true, true, true, true, true, true }; // False means no force and torque will be applied to specified limb.


    // Start is called before the first frame update
    void Start()
    {
        HumanoidSetUp setUp = this.GetComponentInParent <HumanoidSetUp>();

        master = setUp.masterRoot;
        slave  = setUp.slaveRoot;

        slaveTransforms  = slave.GetComponentsInChildren <Transform>();  // Get all transforms in ragdoll.
        masterTransforms = master.GetComponentsInChildren <Transform>(); // Get all transforms in master.

        if (masterTransforms.Length != slaveTransforms.Length)
        {
            Debug.LogWarning("Master transform count does not equal slave transform count." + "\n");
            return;
        }

        numOfRigids             = slave.GetComponentsInChildren <Rigidbody>().Length;
        slaveRigidTransforms    = new Transform[numOfRigids];
        masterRigidTransforms   = new Transform[numOfRigids];
        rigidbodiesPosToCOM     = new Vector3[numOfRigids];
        slaveConfigurableJoints = new ConfigurableJoint[numOfRigids];
        startLocalRotation      = new Quaternion[numOfRigids];
        localToJointSpace       = new Quaternion[numOfRigids];
        forceLastError          = new Vector3[numOfRigids];

        int i = 0, j = 0;

        foreach (Transform t in slaveTransforms)
        {
            if (t.GetComponent <Rigidbody>() != null)
            {
                slaveRigidTransforms[i]  = t;
                masterRigidTransforms[i] = masterTransforms[j];
                rigidbodiesPosToCOM[i]   = Quaternion.Inverse(t.rotation) * (t.GetComponent <Rigidbody>().worldCenterOfMass - t.position);

                ConfigurableJoint cj = t.GetComponent <ConfigurableJoint>();
                if (cj != null) // ragdoll root (hips) doesn't have configurable joint
                {
                    slaveConfigurableJoints[i] = cj;

                    Vector3 forward = Vector3.Cross(cj.axis, cj.secondaryAxis);
                    Vector3 up      = cj.secondaryAxis;

                    localToJointSpace[i]  = Quaternion.LookRotation(forward, up);
                    startLocalRotation[i] = t.localRotation * localToJointSpace[i];

                    jointDrive    = cj.slerpDrive;
                    cj.slerpDrive = jointDrive;
                }
                else if (i != 0) // if it's not root (hips)
                {
                    Debug.LogWarning("Rigidbody " + t + " doesn't have configurable joint" + "\n");
                    return;
                }
                i++;

                t.gameObject.AddComponent <CollisionDetector>();
            }
            j++;
        }

        foreach (Transform t in slaveRigidTransforms)
        {
            t.GetComponent <Rigidbody>().useGravity         = useGravity;
            t.GetComponent <Rigidbody>().angularDrag        = angularDrag;
            t.GetComponent <Rigidbody>().drag               = drag;
            t.GetComponent <Rigidbody>().maxAngularVelocity = maxAngularVelocity;
        }

        EnableJointLimits(true);
    }