Пример #1
0
    void UpdateLift(float dT)
    {
        bool checkLift = controls.IsLift();

        if (checkLift)
        {
            if (IsLifting())
            {
                liftTarget.Drop();
                liftTarget = null;
            }
            else
            {
                Portable curTarget = GetClosestPortable(liftDistanceSquared);
                if (curTarget)
                {
                    liftTarget = curTarget.Lift();
                }
            }
        }

        if (liftTarget != null)
        {
            Rigidbody liftRb = liftTarget.GetComponent <Rigidbody>();

            Quaternion rotationA = avatar.transform.rotation * Quaternion.Euler(0, 90, 0);
            float      angleA    = Quaternion.Angle(liftRb.transform.rotation, rotationA);

            Quaternion rotationB = avatar.transform.rotation * Quaternion.Euler(0, -90, 0);
            float      angleB    = Quaternion.Angle(liftRb.transform.rotation, rotationB);

            Quaternion targetRotation = angleA < angleB ? rotationA : rotationB;
            liftRb.transform.rotation = targetRotation;

            // TODO: Figure out why this has to be stored in a variable, otherwise Portable position doesn't update
            Vector3 liftRBPosition = liftRb.position;
            liftRb.MovePosition(avatarLiftPosition);
        }
    }