/// <summary> /// Moves the physics player to the head position and cancels the movement of the VRCamera by moving the VRRig /// </summary> void DoRoomScaleMovement() { var player = getPlayerCharacter(); Vector3 deltaPosition = _vrCam.transform.localPosition - _lastCamPosition; deltaPosition.y = 0; bool shouldMove = deltaPosition.magnitude > 0.005f; if (shouldMove) { //Check for motion discrepancies if (VHVRConfig.RoomscaleFadeToBlack() && !_fadeManager.IsFadingToBlack) { var lastDeltaMovement = player.m_body.position - _lastPlayerPosition; if (player.m_lastAttachBody && _lastPlayerAttachmentPosition != Vector3.zero) { //Account for ships, and moving attachments lastDeltaMovement -= (player.m_lastAttachBody.position - _lastPlayerAttachmentPosition); } lastDeltaMovement.y = 0; if (roomscaleMovement.magnitude * 0.6f > lastDeltaMovement.magnitude) { SteamVR_Fade.Start(Color.black, 0); SteamVR_Fade.Start(Color.clear, 1.5f); } _lastPlayerPosition = player.m_body.position; _lastPlayerAttachmentPosition = player.m_lastAttachBody ? player.m_lastAttachBody.position : Vector3.zero; } //Calculate new postion _lastCamPosition = _vrCam.transform.localPosition; var globalDeltaPosition = _instance.transform.TransformVector(deltaPosition); globalDeltaPosition.y = 0; roomscaleMovement = globalDeltaPosition; _vrCameraRig.localPosition -= deltaPosition; } else { roomscaleMovement = Vector3.zero; } //Set animation parameters _roomscaleAnimationForwardSpeed = Mathf.SmoothDamp(_roomscaleAnimationForwardSpeed, shouldMove ? deltaPosition.z / Time.fixedDeltaTime : 0, ref _forwardSmoothVel, ROOMSCALE_STEP_ANIMATION_SMOOTHING, 99f); _roomscaleAnimationSideSpeed = Mathf.SmoothDamp(_roomscaleAnimationSideSpeed, shouldMove ? deltaPosition.x / Time.fixedDeltaTime : 0, ref _sideSmoothVel, ROOMSCALE_STEP_ANIMATION_SMOOTHING, 99f); }