public static float CutoffAxis(float value, float deadzone, DeadZoneCutoff cutoff) { if (deadzone < 0f) { deadzone = 0f; } //no larger than 1 if (Mathf.Abs(value) > 1f) { return(Mathf.Sign(value)); } switch (cutoff) { case DeadZoneCutoff.Scaled: if (Mathf.Abs(value) < deadzone) { return(0f); } return(Mathf.Sign(value) * (Mathf.Abs(value) - deadzone) / (1f - deadzone)); case DeadZoneCutoff.Shear: return((Mathf.Abs(value) < deadzone) ? 0f : value); default: return(value); } }
public static Vector2 CutoffDualAxis(Vector2 value, float axleDeadzone, DeadZoneCutoff axleCutoff, float radialDeadzone, DeadZoneCutoff radialCutoff) { if (axleDeadzone < 0f) { axleDeadzone = 0f; } if (radialDeadzone < 0f) { radialDeadzone = 0f; } if (axleDeadzone > 0f) { value.x = CutoffAxis(value.x, axleDeadzone, axleCutoff); value.y = CutoffAxis(value.y, axleDeadzone, axleCutoff); } //no larger than 1 if (value.sqrMagnitude > 1f) { return(value.normalized); } if (radialDeadzone > 0f) { switch (radialCutoff) { case DeadZoneCutoff.Scaled: if (value.sqrMagnitude < radialDeadzone * radialDeadzone) { return(Vector2.zero); } value = value.normalized * (value.magnitude - radialDeadzone) / (1f - radialDeadzone); break; case DeadZoneCutoff.Shear: if (value.sqrMagnitude < radialDeadzone * radialDeadzone) { value = Vector2.zero; } break; } } return(value); }