Esempio n. 1
0
        private void maybeInitHeadPosition(Player playerCharacter)
        {
            if (!headPositionInitialized && inFirstPerson)
            {
                // First set the position without any adjustment
                Vector3 desiredPosition = getDesiredPosition(playerCharacter);
                _instance.transform.localPosition = desiredPosition - playerCharacter.transform.position;

                if (_headZoomLevel != HeadZoomLevel.FirstPerson)
                {
                    _instance.transform.localPosition += getHeadOffset(_headZoomLevel);
                }
                else
                {
                    setPlayerVisualsOffset(playerCharacter.transform, -getHeadOffset(_headZoomLevel));
                }

                var hmd = Valve.VR.InteractionSystem.Player.instance.hmdTransform;
                // Measure the distance between HMD and desires location, and save it.
                FIRST_PERSON_HEIGHT_OFFSET = desiredPosition.y - hmd.position.y;
                if (VHVRConfig.UseLookLocomotion())
                {
                    _instance.transform.localRotation = Quaternion.Euler(0f, -hmd.localRotation.eulerAngles.y, 0f);
                }
                headPositionInitialized = true;

                referencePlayerHeight = Valve.VR.InteractionSystem.Player.instance.eyeHeight;
            }
        }
        public static void Prefix(Player __instance, ref Quaternion ___m_lookYaw, CraftingStation ___m_currentStation)
        {
            if (VHVRConfig.NonVrPlayer() ||
                __instance != Player.m_localPlayer ||
                !VRPlayer.attachedToPlayer ||
                !VRPlayer.inFirstPerson ||
                !VHVRConfig.UseLookLocomotion() ||
                ___m_currentStation != null /* Not Crafting */)
            {
                return;
            }

            /* Not attached to something, like boat controls */
            if (__instance.IsAttached())
            {
                //Apply ship rotation
                if (__instance.m_attached && __instance.m_attachPoint)
                {
                    // Rotate VRPlayer together with delta ship rotation
                    var newPlayerHeading = __instance.m_attachPoint.forward;
                    newPlayerHeading.y = 0;
                    newPlayerHeading.Normalize();
                    float newHeadingRotation = Quaternion.LookRotation(newPlayerHeading, __instance.transform.up).eulerAngles.y;
                    if (lastAttachmentHeading.HasValue)
                    {
                        ___m_lookYaw *= Quaternion.AngleAxis(newHeadingRotation - lastAttachmentHeading.Value, Vector3.up);
                    }
                    lastAttachmentHeading = newHeadingRotation;
                }
                return;
            }


            // Calculate the current head local rotation
            float currentHeadLocalRotation = Valve.VR.InteractionSystem.Player.instance.hmdTransform.localRotation.eulerAngles.y;

            if (previousHeadLocalRotation.HasValue)
            {
                // Find the difference between the current rotation and previous rotation
                float deltaRotation = currentHeadLocalRotation - previousHeadLocalRotation.Value;

                // Rotate the look yaw by the amount the player rotated their head since last iteration
                ___m_lookYaw *= Quaternion.AngleAxis(deltaRotation, Vector3.up);

                // Rotate the VRPlayer to match the current yaw
                // to offset the rotation the VRPlayer will experience due to rotation of yaw.
                VRPlayer.instance.transform.localRotation *= Quaternion.AngleAxis(-deltaRotation, Vector3.up);
            }

            // Save the current rotation for use in next iteration
            previousHeadLocalRotation = currentHeadLocalRotation;
        }
Esempio n. 3
0
 private bool useDynamicallyPositionedGui()
 {
     return(VRPlayer.attachedToPlayer && VRPlayer.inFirstPerson && VHVRConfig.UseLookLocomotion());
 }