From ff2daa8b95e5921da2f649568e8ff5106b43c437 Mon Sep 17 00:00:00 2001 From: Varneon Date: Tue, 3 Jan 2023 18:28:47 -0800 Subject: [PATCH] Swap VR input exponent to AnimationCurve Closes #1 --- .../com.varneon.vudon.noclip/Noclip.prefab | 37 +++++++++--- .../Runtime/Udon Programs/Noclip.asset | 60 +++++++++---------- .../Runtime/Udon Programs/Noclip.cs | 15 +++-- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/Packages/com.varneon.vudon.noclip/Noclip.prefab b/Packages/com.varneon.vudon.noclip/Noclip.prefab index 44be3ba..5fc3486 100644 --- a/Packages/com.varneon.vudon.noclip/Noclip.prefab +++ b/Packages/com.varneon.vudon.noclip/Noclip.prefab @@ -9,8 +9,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 7617984235308416798} - - component: {fileID: 7617984235308416785} - - component: {fileID: 7617984235308416784} + - component: {fileID: 7117740436155577295} + - component: {fileID: 6077235003161976082} m_Layer: 0 m_Name: Noclip m_TagString: Untagged @@ -32,7 +32,7 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &7617984235308416785 +--- !u!114 &7117740436155577295 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -53,16 +53,39 @@ MonoBehaviour: PrefabModificationsReferencedUnityObjects: [] PrefabModifications: [] SerializationNodes: [] - _udonSharpBackingUdonBehaviour: {fileID: 7617984235308416784} + _udonSharpBackingUdonBehaviour: {fileID: 6077235003161976082} noclipTriggerMethod: 0 toggleThreshold: 0.25 speed: 15 - vrSpeedExponent: 2 + vrInputMultiplier: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 desktopSpeedFraction: 0.25 desktopVerticalInput: 1 upKey: 101 downKey: 113 ---- !u!114 &7617984235308416784 +--- !u!114 &6077235003161976082 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -81,7 +104,7 @@ MonoBehaviour: SynchronizePosition: 0 AllowCollisionOwnershipTransfer: 0 Reliable: 0 - _syncMethod: 1 + _syncMethod: 0 serializedProgramAsset: {fileID: 11400000, guid: e9cf694ca30d71e42ac2f35b1ec6a93f, type: 2} programSource: {fileID: 11400000, guid: 51ead3bb0841106499e15c410ba8685c, type: 2} diff --git a/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.asset b/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.asset index 6873da1..158cc12 100644 --- a/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.asset +++ b/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.asset @@ -308,19 +308,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: vrSpeedExponent + Data: vrInputMultiplier - Name: $v Entry: 7 Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: vrSpeedExponent + Data: vrInputMultiplier - Name: k__BackingField - Entry: 9 - Data: 10 + Entry: 7 + Data: 23|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: UnityEngine.AnimationCurve, UnityEngine.CoreModule + - Name: + Entry: 8 + Data: - Name: k__BackingField Entry: 9 - Data: 10 + Data: 23 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -335,53 +341,47 @@ MonoBehaviour: Data: true - Name: _fieldAttributes Entry: 7 - Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 - Data: 5 + Data: 4 - Name: Entry: 7 - Data: 24|UnityEngine.SerializeField, UnityEngine.CoreModule + Data: 25|UnityEngine.SerializeField, UnityEngine.CoreModule - Name: Entry: 8 Data: - Name: Entry: 7 - Data: 25|UnityEngine.TooltipAttribute, UnityEngine.CoreModule - - Name: tooltip + Data: 26|Varneon.VInspector.FieldParentElementAttribute, Varneon.V-Inspector.Runtime + - Name: ParentName Entry: 1 - Data: '[1 = Linear input curve | 1< = Exponential input curve] Helps with ''crawling'' - slowly when just slightly moving joystick even with higher standard speed' - - Name: - Entry: 8 - Data: - - Name: - Entry: 7 - Data: 26|UnityEngine.RangeAttribute, UnityEngine.CoreModule - - Name: min - Entry: 4 - Data: 1 - - Name: max - Entry: 4 - Data: 5 + Data: Foldout_VR - Name: Entry: 8 Data: - Name: Entry: 7 - Data: 27|Varneon.VInspector.FieldParentElementAttribute, Varneon.V-Inspector.Runtime - - Name: ParentName + Data: 27|Varneon.VInspector.FieldLabelAttribute, Varneon.V-Inspector.Runtime + - Name: FieldName Entry: 1 - Data: Foldout_VR + Data: Input Exponent - Name: Entry: 8 Data: - Name: Entry: 7 - Data: 28|Varneon.VInspector.FieldLabelAttribute, Varneon.V-Inspector.Runtime - - Name: FieldName + Data: 28|UnityEngine.TooltipAttribute, UnityEngine.CoreModule + - Name: tooltip Entry: 1 - Data: Input Exponent + Data: 'Input speed multiplier curve for VR. + + + Horizontal (0-1): VR + movement input magnitude + + + Vertical (0-1): Speed multiplier' - Name: Entry: 8 Data: diff --git a/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.cs b/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.cs index 36f2580..9c5d1c9 100644 --- a/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.cs +++ b/Packages/com.varneon.vudon.noclip/Runtime/Udon Programs/Noclip.cs @@ -43,14 +43,13 @@ public class Noclip : UdonSharpBehaviour private float speed = 15f; /// - /// Exponent of the linear input for raising the speed to the power of + /// Input speed multiplier curve for VR /// [SerializeField] - [Tooltip("[1 = Linear input curve | 1< = Exponential input curve] Helps with 'crawling' slowly when just slightly moving joystick even with higher standard speed")] - [Range(1f, 5f)] [FieldParentElement("Foldout_VR")] [FieldLabel("Input Exponent")] - private float vrSpeedExponent = 2f; + [Tooltip("Input speed multiplier curve for VR.\n\nHorizontal (0-1): VR movement input magnitude\n\nVertical (0-1): Speed multiplier")] + private AnimationCurve vrInputMultiplier = new AnimationCurve(new Keyframe(0f, 0f, 0f, 0f), new Keyframe(1f, 1f, 2f, 2f)); /// /// Speed multiplier when Shift is not pressed @@ -184,17 +183,17 @@ private void LateUpdate() if (vrEnabled) { - // Get magnitude of the movement input to apply shared exponential velocity - float exponentialInputMagnitude = Mathf.Pow(new Vector2(inputMoveHorizontal, inputMoveVertical).magnitude, vrSpeedExponent); + // Get the movement input vector + Vector3 movementInputVector = new Vector3(inputMoveHorizontal, 0f, inputMoveVertical); // Get the maximum delta magnitude float deltaTimeSpeed = deltaTime * speed; // Create a delta vector for local X and Z axes - Vector3 xzDelta = deltaTimeSpeed * exponentialInputMagnitude * new Vector3(inputMoveHorizontal, 0f, inputMoveVertical); + Vector3 xzDelta = deltaTimeSpeed * vrInputMultiplier.Evaluate(movementInputVector.magnitude) * movementInputVector.normalized; // Create a delta vector for world Y axis - Vector3 yWorldDelta = new Vector3(0f, Mathf.Pow(Mathf.Abs(inputLookVertical), vrSpeedExponent) * Mathf.Sign(inputLookVertical) * deltaTimeSpeed, 0f); + Vector3 yWorldDelta = new Vector3(0f, vrInputMultiplier.Evaluate(Mathf.Abs(inputLookVertical)) * Mathf.Sign(inputLookVertical) * deltaTimeSpeed, 0f); // Apply the position changes position += headRot * xzDelta + yWorldDelta;