Skip to content

Commit

Permalink
Swap VR input exponent to AnimationCurve
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
Varneon committed Jan 4, 2023
1 parent 6f62b5c commit ff2daa8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
37 changes: 30 additions & 7 deletions Packages/com.varneon.vudon.noclip/Noclip.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Name>k__BackingField
Entry: 1
Data: vrSpeedExponent
Data: vrInputMultiplier
- Name: <UserType>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: <SystemType>k__BackingField
Entry: 9
Data: 10
Data: 23
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ public class Noclip : UdonSharpBehaviour
private float speed = 15f;

/// <summary>
/// Exponent of the linear input for raising the speed to the power of
/// Input speed multiplier curve for VR
/// </summary>
[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));

/// <summary>
/// Speed multiplier when Shift is not pressed
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ff2daa8

Please sign in to comment.