diff --git a/lua/config.lua b/lua/config.lua index 3100389..452036e 100644 --- a/lua/config.lua +++ b/lua/config.lua @@ -10,16 +10,11 @@ return { BRAKE_SLIP_THRESHOLD = 7, -- wheel slip threshold for brake slip vibration (0-100) BRAKE_SLIP_VIBRATION_FREQUENCY = 255, -- frequency of brake slip vibration (0-255) BRAKE_VALUE_MIN = 0.1, -- minimum brake value for brake resistance calculation (0-1) - BRAKE_VALUE_MAX = 0.6, -- maximum brake value for brake resistance calculation (0-1) - BRAKE_RESISTANCE_MIN = 10, -- minimum brake resistance (0-255) - BRAKE_RESISTANCE_MAX = 130, -- maximum brake resistance (0-255) - BRAKE_AIRSPEED_MAX = 60, -- maximum airspeed for brake force calculation (kmh/h) - BRAKE_FORCE_MIN = 100, -- minimum brake force (0-255) + BRAKE_VALUE_MAX = 0.5, -- maximum brake value for brake resistance calculation (0-1) + BRAKE_AIRSPEED_MAX = 120, -- maximum airspeed for brake force calculation (kmh/h) + BRAKE_FORCE_MIN = 50, -- minimum brake force (0-255) BRAKE_FORCE_MAX = 255, -- maximum brake force (0-255) - THROTTLE_VALUE_MIN = 0.4, -- minimum throttle value for throttle resistance calculation (0-1) - THROTTLE_VALUE_MAX = 1, -- maximum throttle value for throttle resistance calculation (0-1) - THROTTLE_RESISTANCE_MIN = 25, -- minimum throttle resistance (0-255) - THROTTLE_RESISTANCE_MAX = 100, -- maximum throttle resistance (0-255) + THROTTLE_RESISTANCE_START = 110, -- minimum throttle resistance (0-255) DAMAGE_LED_COLOR = { r = 255, -- red component (0-255) g = 0, -- green component (0-255) diff --git a/lua/vehicle/extensions/auto/dsx.lua b/lua/vehicle/extensions/auto/dsx.lua index de65501..cec9379 100644 --- a/lua/vehicle/extensions/auto/dsx.lua +++ b/lua/vehicle/extensions/auto/dsx.lua @@ -112,6 +112,16 @@ function inverseLerp(a, b, v) return 0 end +local function calculateCombinedForce(brake, speed) + local brakeNormalized = math.max(0, math.min(1, (brake - CONFIG.BRAKE_VALUE_MIN) / + (CONFIG.BRAKE_VALUE_MAX - CONFIG.BRAKE_VALUE_MIN))) + local speedNormalized = math.min(1.0, speed / CONFIG.BRAKE_AIRSPEED_MAX) + + local combinedFactor = brakeNormalized * speedNormalized + + return math.min(255, lerp(CONFIG.BRAKE_FORCE_MIN, CONFIG.BRAKE_FORCE_MAX, combinedFactor)) +end + local function handleLeftTrigger() local absActive = state.isABSActive and (socket.gettime() - state.absActivationTime) > CONFIG.ABS_WAIT_TIME @@ -133,17 +143,11 @@ local function handleLeftTrigger() 1, 0, 0, 0, 0, 0} } else - local brakeIntensity = lerp(CONFIG.BRAKE_VALUE_MIN, CONFIG.BRAKE_VALUE_MAX, state.brake) - local startOfResistance = lerp(CONFIG.BRAKE_RESISTANCE_MIN, CONFIG.BRAKE_RESISTANCE_MAX, brakeIntensity) - local airSpeedFactor = math.min(1.0, state.airSpeedKmh / CONFIG.BRAKE_AIRSPEED_MAX) - local amountOfForceExcerted = math.min(255, - lerp(CONFIG.BRAKE_FORCE_MIN, CONFIG.BRAKE_FORCE_MAX, airSpeedFactor)) - return { type = Triggers.InstructionType.TriggerUpdate, parameters = {CONFIG.CONTROLLER_INDEX, Triggers.Trigger.Left, Triggers.TriggerMode.CustomTriggerValue, - Triggers.CustomTriggerValueMode.Rigid, startOfResistance, amountOfForceExcerted, 255, 0, - 0, 0, 0} + Triggers.CustomTriggerValueMode.Rigid, CONFIG.BRAKE_VALUE_MIN * 255, + calculateCombinedForce(state.brake, state.airSpeedKmh), 0, 0, 0, 0, 0} } end end @@ -159,14 +163,10 @@ local function handleRightTrigger() Triggers.CustomTriggerValueMode.VibratePulse, 255, 255, 3, 50, 0, 0, 0} } else - local startOfResistanceThrottle = 1 * lerp(CONFIG.THROTTLE_VALUE_MIN, CONFIG.THROTTLE_VALUE_MIN, state.throttle) - local startOfResistance = lerp(CONFIG.THROTTLE_RESISTANCE_MIN, CONFIG.THROTTLE_RESISTANCE_MAX, - startOfResistanceThrottle) - return { type = Triggers.InstructionType.TriggerUpdate, parameters = {CONFIG.CONTROLLER_INDEX, Triggers.Trigger.Right, Triggers.TriggerMode.CustomTriggerValue, - Triggers.CustomTriggerValueMode.Rigid, startOfResistance, 0, 0, 0, 0, 0, 0} + Triggers.CustomTriggerValueMode.Rigid, CONFIG.THROTTLE_RESISTANCE_START, 0, 0, 0, 0, 0, 0} } end end @@ -289,15 +289,16 @@ local function updateGFX(dt) maxRPM = engines[1]:getTorqueData().maxRPM end + local isAbsActive = electrics.values.absActive == 1 local rpm = electrics.values.rpm or 0 - if isABSActive and not state.isABSActive then + if isAbsActive and not state.isABSActive then state.absActivationTime = socket.gettime() end state.throttle = input.state.throttle.val state.brake = input.state.brake.val - state.isABSActive = electrics.values.absActive == 1 + state.isABSActive = isAbsActive state.airSpeedKmh = electrics.values.airspeed * 3.6 state.beamDamage = beamstate.damage state.wheelSlip = wheelSlip