Exemplo n.º 1
0
        public void ClearVelocities()
        {
            rigidbody.velocity        = Vector3.zero;
            rigidbody.angularVelocity = Vector3.zero;

            targetVelocity             = Vector3.zero;
            targetAnimatedCenterOfMass = V3Tools.TransformPointUnscaled(target, rigidbody.centerOfMass);
        }
Exemplo n.º 2
0
        public void Read()
        {
            Vector3 tAM = V3Tools.TransformPointUnscaled(target, rigidbody.centerOfMass);

            targetVelocity             = (tAM - targetAnimatedCenterOfMass) / Time.deltaTime;
            targetAnimatedCenterOfMass = tAM;

            if (joint.connectedBody != null)
            {
                targetAnimatedRotation = targetLocalRotation * localRotationConvert;
            }

            targetAnimatedWorldRotation = target.rotation;
        }
Exemplo n.º 3
0
        public void Initiate(MuscleLite[] colleagues)
        {
            name      = joint.name;
            transform = joint.transform;
            rigidbody = joint.GetComponent <Rigidbody>();

            if (joint.connectedBody != null)
            {
                for (int i = 0; i < colleagues.Length; i++)
                {
                    if (colleagues[i].joint.GetComponent <Rigidbody>() == joint.connectedBody)
                    {
                        connectedBodyTarget = colleagues[i].target;
                    }
                    if (colleagues[i] == this)
                    {
                        index = i;
                    }
                }

                joint.autoConfigureConnectedAnchor = false;
                connectedBodyTransform             = joint.connectedBody.transform;

                directTargetParent = target.parent == connectedBodyTarget;
            }

            targetParent         = connectedBodyTarget != null ? connectedBodyTarget : target.parent;
            toParentSpace        = Quaternion.Inverse(targetParentRotation) * parentRotation;
            localRotationConvert = Quaternion.Inverse(targetLocalRotation) * localRotation;

            // Joint space
            Vector3 forward = Vector3.Cross(joint.axis, joint.secondaryAxis).normalized;
            Vector3 up      = Vector3.Cross(forward, joint.axis).normalized;

            defaultLocalRotation = localRotation;
            Quaternion toJointSpace = Quaternion.LookRotation(forward, up);

            toJointSpaceInverse = Quaternion.Inverse(toJointSpace);
            toJointSpaceDefault = defaultLocalRotation * toJointSpace;

            // Set joint params
            joint.rotationDriveMode      = RotationDriveMode.Slerp;
            joint.configuredInWorldSpace = false;

            // Fix target Transforms
            defaultTargetLocalPosition = target.localPosition;
            defaultTargetLocalRotation = target.localRotation;
            targetAnimatedCenterOfMass = V3Tools.TransformPointUnscaled(target, rigidbody.centerOfMass);

            // Resetting
            if (joint.connectedBody == null)
            {
                defaultPosition = transform.localPosition;
                defaultRotation = transform.localRotation;
            }
            else
            {
                defaultPosition = joint.connectedBody.transform.InverseTransformPoint(transform.position);
                defaultRotation = Quaternion.Inverse(joint.connectedBody.transform.rotation) * transform.rotation;
            }

            rigidbody.isKinematic = false;

            Read();

            initiated = true;
        }