Skip to content

Commit 6e7c7de

Browse files
committed
fix(Transformation): provide deadzone value for float
There was an issue where the minimum float value for an axis could be so low that it just wasn't reported by Unity as an action meaning any subsequent action may not get updated due to the value not being recognised as changed. This fix adds in an extra deadzone value to the float that can be used to set the absolute minimum reported value to consider as zero.
1 parent 6bcb26f commit 6e7c7de

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Runtime/SharedResources/Scripts/Transformation/Conversion/CallbackContextToFloat.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace Tilia.Input.UnityInputSystem.Transformation.Conversion
22
{
3+
using Malimbe.PropertySerializationAttribute;
4+
using Malimbe.XmlDocumentationAttribute;
35
using System;
46
using UnityEngine.Events;
57
using UnityEngine.InputSystem;
@@ -15,14 +17,22 @@ public class CallbackContextToFloat : CallbackContextTransformer<float, Callback
1517
[Serializable]
1618
public class UnityEvent : UnityEvent<float> { }
1719

20+
/// <summary>
21+
/// The minimum value to consider as a zero float value.
22+
/// </summary>
23+
[Serialized]
24+
[field: DocumentedByXml]
25+
public float DeadZoneValue { get; set; } = 0.00001f;
26+
1827
/// <summary>
1928
/// Transforms the given input <see cref="InputAction.CallbackContext"/> to the equivalent <see cref="float"/> value.
2029
/// </summary>
2130
/// <param name="input">The value to transform.</param>
2231
/// <returns>The transformed value.</returns>
2332
protected override float Process(InputAction.CallbackContext input)
2433
{
25-
return input.ReadValue<float>();
34+
float value = input.ReadValue<float>();
35+
return value >= DeadZoneValue ? value : 0f;
2636
}
2737
}
2838
}

0 commit comments

Comments
 (0)