/// <summary> /// Handle the speed progression for the player object /// </summary> private void HandleSpeed() { // only update target speed factor if touchpad is being touched if (OVRInput.Get(OVRInput.Touch.PrimaryTouchpad)) { int totalStepsSum = ForwardSpeedSteps + BackwardSpeedSteps; var speedTouchPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); // + 1 to only have positive values, divided by 2 to have range 0 to 1 // results in normalized input var normalizedInput = (speedTouchPosition.y + 1) / 2; // calculate targeted speed step and then _targetSpeedFactor = normalizedInput * totalStepsSum; // remove offset due to normalization _targetSpeedFactor -= BackwardSpeedSteps; } _currentSpeedFactor = MovementCalculationHelper.UpdateSpeedFactor(_currentSpeedFactor, _targetSpeedFactor, Acceleration); // update UI elements if (CurrentSpeedTransform != null) { CurrentSpeedTransform.localScale = new Vector3(1, _currentSpeedFactor * ScaleValuePerSpeedStep, 1); } if (TargetSpeedTransform != null) { TargetSpeedTransform.localScale = new Vector3(1, _targetSpeedFactor * ScaleValuePerSpeedStep, 1); } MovementCalculationHelper.ApplyMovementTranslation(transform, BaseMovementSpeed, _currentSpeedFactor); }
/// <summary> /// calculates current rotational input and updates ship orientation aswell as cockpit UI elements accordingly /// </summary> private void HandleRotation() { // movement can be disabled to relax hand and give the user the option of letting the controller go w/o affecting flight if (_movementEnabled) { var rotation = GetRotationQuaternion(); var yawFactor = MovementCalculationHelper.CalculateYawFactor(rotation, _deadzoneHandler); var pitchFactor = MovementCalculationHelper.CalculatePitchFactor(rotation, _deadzoneHandler); var rollFactor = MovementCalculationHelper.CalculateRollFactor(rotation, _deadzoneHandler); // do rotate, based on specified rotation speeds transform.Rotate(yawFactor * YawRotationSpeed, pitchFactor * PitchRotationSpeed, rollFactor * RollRotationSpeed); // update UI elements inside cockpit UpdateRotationSliders(yawFactor, pitchFactor, rollFactor); UpdateMiniShipHologram(yawFactor, pitchFactor, rollFactor); // check if user requested movement disabling if (OVRInput.GetUp(OVRInput.Button.PrimaryTouchpad)) { DisableMovement(); } } else { // check if user requested movement enabling if (OVRInput.GetUp(OVRInput.Button.PrimaryTouchpad)) { EnableMovement(); } } }
public void UpdateSpeedFactor_Returns_Correct_Value_With_Remaining_Speed() { var expectedResult = 0f; var result = MovementCalculationHelper.UpdateSpeedFactor(2f, 0f, 2f); Assert.AreEqual(expectedResult, result); }
public void UpdateSpeedFactor_Returns_0_If_Input_0() { var expectedResult = 0f; var result = MovementCalculationHelper.UpdateSpeedFactor(0, 0, 0); Assert.AreEqual(expectedResult, result); }
public void UpdateSpeedFactor_Returns_Correct_Value_With_Simple_Input() { var expectedResult = 2f; var result = MovementCalculationHelper.UpdateSpeedFactor(1f, 2f, 1f); Assert.AreEqual(expectedResult, result); }