From 3e05056af78f8c0b575d951c151bf0a71b9513c8 Mon Sep 17 00:00:00 2001 From: Harvey Ball Date: Sat, 19 Aug 2017 08:01:59 +0100 Subject: [PATCH] fix(Utilities): use local space for velocity estimation samples The Velocity Estimator was using world space to determine the samples for velocity and angular velocity, which would cause problems if the Velocity Estimator was attached to a GameObject that's parent was rotated. It could be seen in the Unity SDK by simply rotating the CameraRig around the Y axis and then the throwing mechanism would throw things in the wrong direction. The solution is to simply use local space for position and rotation as then the actual object the Velocity Estimator is attached to will be used for the relative position and rotation. --- .../VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Assets/VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs b/Assets/VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs index e23a2c1a5..cd33f58a4 100644 --- a/Assets/VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs +++ b/Assets/VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs @@ -137,8 +137,8 @@ protected virtual IEnumerator EstimateVelocity() { currentSampleCount = 0; - Vector3 previousPosition = transform.position; - Quaternion previousRotation = transform.rotation; + Vector3 previousPosition = transform.localPosition; + Quaternion previousRotation = transform.localRotation; while (true) { yield return new WaitForEndOfFrame(); @@ -149,8 +149,8 @@ protected virtual IEnumerator EstimateVelocity() int w = currentSampleCount % angularVelocitySamples.Length; currentSampleCount++; - velocitySamples[v] = velocityFactor * (transform.position - previousPosition); - Quaternion deltaRotation = transform.rotation * Quaternion.Inverse(previousRotation); + velocitySamples[v] = velocityFactor * (transform.localPosition - previousPosition); + Quaternion deltaRotation = transform.localRotation * Quaternion.Inverse(previousRotation); float theta = 2.0f * Mathf.Acos(Mathf.Clamp(deltaRotation.w, -1.0f, 1.0f)); if (theta > Mathf.PI) @@ -166,8 +166,8 @@ protected virtual IEnumerator EstimateVelocity() angularVelocitySamples[w] = angularVelocity; - previousPosition = transform.position; - previousRotation = transform.rotation; + previousPosition = transform.localPosition; + previousRotation = transform.localRotation; } } }