Example #1
0
            static void PatchTurning(PlayerCharacterController __instance)
            {
                if (OWInput.GetInputMode() != InputMode.Character)
                {
                    return;
                }

                var playerCam = __instance.GetValue <OWCamera>("_playerCam");
                var transform = __instance.GetValue <Transform>("_transform");

                Quaternion fromTo = Quaternion.FromToRotation(transform.forward, Vector3.ProjectOnPlane(playerCam.transform.forward, transform.up));

                var magnitudeUp      = 1 - Vector3.ProjectOnPlane(playerCam.transform.up, transform.up).magnitude;
                var magnitudeForward = 1 - Vector3.ProjectOnPlane(playerCam.transform.up, transform.right).magnitude;
                var magnitude        = magnitudeUp + magnitudeForward;

                if (magnitude < 0.3f)
                {
                    return;
                }

                var targetRotation  = fromTo * transform.rotation;
                var inverseRotation = Quaternion.Inverse(fromTo) * _playArea.rotation;

                var maxDegreesDelta = magnitude * 3f;

                _playArea.rotation = Quaternion.RotateTowards(_playArea.rotation, inverseRotation, maxDegreesDelta);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, maxDegreesDelta);
            }