Beispiel #1
0
    private void Smooth(ref float angle, float angleTarget, ref float speed, BodyPartPivot tr)
    {
        if (float.IsNaN(speed))
        {
            speed = 0.0f;
        }

        if (!tr.BodyPart.Rigidbody.isKinematic)
        {
            return;
        }

        float smoothTime = 0.05f;

        angle = Mathf.SmoothDampAngle(angle, angleTarget, ref speed, smoothTime);
        tr.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
Beispiel #2
0
    private static void SetupPivot(BodyPartPivot pivot, out float angle)
    {
        BodyPart bodyPart = pivot.BodyPart;

        if (!bodyPart.Rigidbody.isKinematic)
        {
            angle = 0.0f;
            return;
        }
        Transform  childPivot = bodyPart.ChildPivot;
        Vector3    pos        = bodyPart.transform.position;
        Quaternion rot        = bodyPart.transform.rotation;

        pivot.transform.position    = childPivot.position;
        pivot.transform.rotation    = childPivot.rotation;
        bodyPart.transform.position = pos;
        bodyPart.transform.rotation = rot;

        angle = Vector2.Angle(Vector2.right, pivot.transform.right);
        if (pivot.transform.right.y < 0.0f)
        {
            angle = -angle;
        }
    }