public void Event_Translation_Gain(float g_t, Vector3 translationApplied) { if (state == LoggingState.logging) { //if (testing) //{ // g_t = 1; // translationApplied = Vector2.up; //} sumOfInjectedTranslation += translationApplied.magnitude; maxTranslationGain = Mathf.Max(maxTranslationGain, g_t); minTranslationGain = Mathf.Min(minTranslationGain, g_t); sumOfVirtualDistanceTravelled += Mathf.Sign(g_t) * translationApplied.magnitude; // if gain is positive, redirection reference moves with the user, thus increasing the virtual displacement, and if negative, decreases virtualDistanceTravelledSinceLastReset += Mathf.Sign(g_t) * translationApplied.magnitude; //translationGainSamplesBuffer.Add(Mathf.Abs(g_t) * redirectionManager.userMovementManager.lastDeltaTime); // The proper way is using redirectionManager.userMovementManager.lastDeltaTime which is the true time the gain was applied for, but this causes problems when we have a long frame and then a short frame // But we'll artificially use this current delta time instead! //translationGainSamplesBuffer.Add(g_t * redirectionManager.userMovementManager.lastDeltaTime); //print("Translation Gain: " + g_t + "\tInterval: " + redirectionManager.getDeltaTime()); translationGainSamplesBuffer.Add(g_t * simulationManager.GetDeltaTime()); //injectedTranslationSamplesBuffer.Add(translationApplied.magnitude * redirectionManager.userMovementManager.lastDeltaTime); injectedTranslationSamplesBuffer.Add(translationApplied.magnitude * simulationManager.GetDeltaTime()); } }
public void RotateIfNecessary(float rotationToTargetInDegrees, Vector3 userToTargetVectorFlat) { // Handle Rotation To Waypoint float rotationToApplyInDegrees = Mathf.Sign(rotationToTargetInDegrees) * Mathf.Min(simulationManager.GetDeltaTime() * rotationSpeed, Mathf.Abs(rotationToTargetInDegrees)); // Only rotate if you have a reasonable distance to target // I'm not happy with this hack and I'm not sure how to explain the behavior because it keeps trying to rotate until the user faces southeast and then it stops! //if (!UserController.Approximately(userToWaypointVector2D, Vector2.zero)) // Preventing Rotation When At Waypoint By Checking If Distance Is Sufficient //print("rotationToApplyInDegrees: " + rotationToApplyInDegrees); if (userToTargetVectorFlat.magnitude > MINIMUM_DISTANCE_TO_WAYPOINT_FOR_ROTATION) { transform.Rotate(Vector3.up, rotationToApplyInDegrees, Space.World); } }