Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value calculation for LevelBehaviour when rotating clockwise over 0 #133

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Runtime/Input/InteractionBehaviours/LeverBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ private void UpdateValue()
if (valueMapping == ValueMapping.Value0To1)
{
Value = new(
TransformX ? leverPose.x / ranges.x + .5f : 0f,
TransformY ? leverPose.y / ranges.y + .5f : 0f,
TransformZ ? leverPose.z / ranges.z + .5f : 0f);
TransformX ? GetNormalizedAxisValue01(leverPose.x, minimumValues.x, maximumValues.x) : 0f,
TransformY ? GetNormalizedAxisValue01(leverPose.y, minimumValues.y, maximumValues.y) : 0f,
TransformZ ? GetNormalizedAxisValue01(leverPose.z, minimumValues.z, maximumValues.z) : 0f);

return;
}
Expand Down Expand Up @@ -463,6 +463,8 @@ private void SnapIntoPlace()

#region Utilities

private float GetNormalizedAxisValue01(float leverPose, float minimumValue, float maximumValue) => (WrapAngle(leverPose) - minimumValue) / (maximumValue - minimumValue);

private Vector3 GetInteractorPosition() => pivot.InverseTransformPoint(currentInteractor.GameObject.transform.position);

private Vector3 GetInteractorRotation() => (Quaternion.Inverse(pivot.rotation) * currentInteractor.GameObject.transform.rotation).eulerAngles;
Expand Down Expand Up @@ -583,6 +585,18 @@ private float ClampAngle(float angle, float from, float to)
return Mathf.Min(angle, to);
}

private static float WrapAngle(float angle)
{
angle %= 360;

if (angle > 180)
{
return angle - 360;
}

return angle;
}

#endregion Utilities
}
}
Loading