diff --git a/koptilnya/engine_remastered/configs/new_sx240.txt b/koptilnya/engine_remastered/configs/new_sx240.txt index bf1384e..78b76d1 100644 --- a/koptilnya/engine_remastered/configs/new_sx240.txt +++ b/koptilnya/engine_remastered/configs/new_sx240.txt @@ -6,14 +6,50 @@ local Vehicle, POWERTRAIN_COMPONENT = unpack(require('/koptilnya/engine_remastered/vehicle.txt')) local Differential = require('/koptilnya/engine_remastered/powertrain/differential.txt') +-- Michelin Pilot Sport 4S (High-Performance Road Tire) local WheelConfig = { DEBUG = true, BrakePower = 1200, - CustomWheel = { Mass = 80 }, + CustomWheel = { + Mass = 30, + + LateralFrictionPreset = { + B = 12.0, + C = 1.3, + D = 1.8, + E = -1.8 + }, + LongitudinalFrictionPreset = { + B = 18.0, + C = 1.5, + D = 1.5, + E = 0.3 + }, + AligningFrictionPreset = { + B = 2.8, + C = 2.1, + D = 0.10, + E = -2.5 + }, + }, Model = 'models/sprops/trans/wheel_a/wheel25.mdl' } -local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 33, CustomWheel = { CasterAngle = 3 } }) -local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2200 }) +local FrontWheelsConfig = table.merge( + table.copy(WheelConfig), + { + SteerLock = 33, + CustomWheel = { + CasterAngle = 3 + } + } +) + +local RearWheelsConfig = table.merge( + table.copy(WheelConfig), + { + HandbrakePower = 2200 + } +) Vehicle:new({ { @@ -77,13 +113,13 @@ Vehicle:new({ Name = 'WheelFL', Type = POWERTRAIN_COMPONENT.Wheel, Input = 'AxleFront', - Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 0, CustomWheel = { CamberAngle = -3, ToeAngle = -0.5 } }) + Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 0, CustomWheel = { CamberAngle = -3, ToeAngle = 0.5 } }) }, { Name = 'WheelFR', Type = POWERTRAIN_COMPONENT.Wheel, Input = 'AxleFront', - Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 180, CustomWheel = { CamberAngle = 3, ToeAngle = 0.5 } }) + Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 180, CustomWheel = { CamberAngle = -3, ToeAngle = 0.5 } }) }, { Name = 'AxleBack', @@ -119,12 +155,12 @@ Vehicle:new({ Name = 'WheelRL', Input = 'AxleBack', Type = POWERTRAIN_COMPONENT.Wheel, - Config = table.merge(table.copy(RearWheelsConfig), { Offset = 0, CustomWheel = { CamberAngle = -1, ToeAngle = -0.5 } }) + Config = table.merge(table.copy(RearWheelsConfig), { Offset = 0, CustomWheel = { CamberAngle = -1, ToeAngle = 0.5 } }) }, { Name = 'WheelRR', Input = 'AxleBack', Type = POWERTRAIN_COMPONENT.Wheel, - Config = table.merge(table.copy(RearWheelsConfig), { Offset = 180, CustomWheel = { CamberAngle = 1, ToeAngle = 0.5 } }) + Config = table.merge(table.copy(RearWheelsConfig), { Offset = 180, CustomWheel = { CamberAngle = -1, ToeAngle = 0.5 } }) } }) diff --git a/koptilnya/engine_remastered/powertrain/differential.txt b/koptilnya/engine_remastered/powertrain/differential.txt index 0a17f81..506945f 100644 --- a/koptilnya/engine_remastered/powertrain/differential.txt +++ b/koptilnya/engine_remastered/powertrain/differential.txt @@ -116,16 +116,27 @@ function Differential:forwardStep(torque, inertia) -- // REFACTOR if self.steerLock ~= 0 then local steerInertia = (aI + bI) / 2 - local inputForce = 228.0 + local driverInput = 5 + + local localVelocityLength = chip():getVelocity():getLength() + local MPH = localVelocityLength * (15 / 352) + local KPH = MPH * 1.609 + + local assist = math.clamp(10.0 / math.sqrt(KPH / 3), 2.0, 10.0) + local inputForce = driverInput * assist + local maxSteerSpeed = math.rad(1337) local inputTorque = self.vehicle.steer * inputForce local avgSteerAngle = (self.outputA.customWheel.steerAngle + self.outputB.customWheel.steerAngle) / 2 local mz = self.outputA.customWheel.mz + self.outputB.customWheel.mz + local mzDiff = self.outputA.customWheel.mz - self.outputB.customWheel.mz local avgMz = (self.outputA.customWheel.mz + self.outputB.customWheel.mz) / 2 local maxMz = math.max(self.outputA.customWheel.mz + self.outputB.customWheel.mz) - local steerTorque = mz * -1 + inputTorque + local minMz = math.min(self.outputA.customWheel.mz + self.outputB.customWheel.mz) + + local steerTorque = mzDiff * -1 + inputTorque local steerAngularAccel = steerTorque / steerInertia diff --git a/koptilnya/engine_remastered/powertrain/wheel.txt b/koptilnya/engine_remastered/powertrain/wheel.txt index c0ee60f..33ecdb1 100644 --- a/koptilnya/engine_remastered/powertrain/wheel.txt +++ b/koptilnya/engine_remastered/powertrain/wheel.txt @@ -11,7 +11,7 @@ require('/koptilnya/libs/entity.txt') local Wheel = class('Wheel', PowertrainComponent) -local DEBUG = false +local DEBUG = true function Wheel:initialize(vehicle, name, config) PowertrainComponent.initialize(self, vehicle, name, config) @@ -50,6 +50,8 @@ function Wheel:initialize(vehicle, name, config) self.brakePower = config.BrakePower or 0 self.handbrakePower = config.HandbrakePower or 0 + self.direction = math.sign(math.cos(math.rad(config.Offset or 0))) + self.wireInputs = { [self.name] = 'entity' } @@ -138,15 +140,12 @@ function Wheel:forwardStep(torque, inertia) return 0 end - -- print(inertia) - -- self.customWheel:setInertia(inertia) - - self.customWheel.motorTorque = torque + self.customWheel.motorTorque = torque * self.direction self.customWheel.brakeTorque = math.max(self.brakePower * self.vehicle.brake, self.handbrakePower * self.vehicle.handbrake) self.customWheel:update() - self.angularVelocity = self.customWheel.angularVelocity + self.angularVelocity = self.customWheel.angularVelocity * self.direction if self.customWheel.hasHit and isValid(self.vehicle.basePhysObject) then local surfaceForceVector = self.customWheel.right * self.customWheel.sideFriction.force + self.customWheel.forward * self.customWheel.forwardFriction.force @@ -163,7 +162,7 @@ function Wheel:forwardStep(torque, inertia) local entityAngles = self.entity:getAngles() - self.rot = self.rot + self.angularVelocity * TICK_INTERVAL + self.rot = self.rot + self.angularVelocity * TICK_INTERVAL * self.direction local steerRotated = entityAngles:rotateAroundAxis(self.customWheel.up, nil, math.rad(-self.customWheel.steerAngle) + self.customWheel.toeAngle) local camberRotated = steerRotated:rotateAroundAxis(self.customWheel.forward, nil, -self.customWheel.camberAngle) diff --git a/koptilnya/engine_remastered/wheel/wheel.txt b/koptilnya/engine_remastered/wheel/wheel.txt index 803e09a..abef0a7 100644 --- a/koptilnya/engine_remastered/wheel/wheel.txt +++ b/koptilnya/engine_remastered/wheel/wheel.txt @@ -23,8 +23,10 @@ function Wheel:initialize(config) self.forwardFriction = Friction:new(config.ForwardFriction) self.sideFriction = Friction:new(config.SideFriction) - self.frictionPreset = FrictionPreset:new(config.FrictionPreset) - self.satFrictionPreset = FrictionPreset:new() + + self.lateralFrictionPreset = FrictionPreset:new(config.LateralFrictionPreset) + self.longitudinalFrictionPreset = FrictionPreset:new(config.LongitudinalFrictionPreset) + self.aligningFrictionPreset = FrictionPreset:new(config.AligningFrictionPreset) self.motorTorque = 0 self.brakeTorque = 0 @@ -107,7 +109,7 @@ function Wheel:stepLongitudinal(Tm, Tb, Vx, W, Lc, R, I, kFx, kSx) Tb = math.clamp(Tb, -TbCap, TbCap) W = W + Tb / I * TICK_INTERVAL - local maxTorque = self.frictionPreset:evaluate(math.abs(Sx)) * Lc * kFx * R + local maxTorque = self.longitudinalFrictionPreset:evaluate(math.abs(Sx)) * Lc * kFx * R local errorTorque = (W - Vx / R) * I / TICK_INTERVAL local surfaceTorque = math.clamp(errorTorque, -maxTorque, maxTorque) @@ -143,7 +145,7 @@ function Wheel:stepLateral(Vx, Vy, Lc, kFy, kSy) Sy = Sy * kSy * 0.95 Sy = math.clamp(Sy, -1, 1) local slipSign = Sy < 0 and -1 or 1 - local Fy = -slipSign * self.frictionPreset:evaluate(math.abs(Sy)) * Lc * kFy + local Fy = -slipSign * self.lateralFrictionPreset:evaluate(math.abs(Sy)) * Lc * kFy if Lc < 0.0001 then Sy = 0 @@ -178,10 +180,10 @@ function Wheel:selfAligningTorque(Sy, load) return 0 end - local B = self.satFrictionPreset.B - local C = self.satFrictionPreset.C - local D = self.satFrictionPreset.D - local E = self.satFrictionPreset.E + local B = self.aligningFrictionPreset.B + local C = self.aligningFrictionPreset.C + local D = self.aligningFrictionPreset.D + local E = self.aligningFrictionPreset.E local loadScale = load * 1000 local mechanicalTrail = 0.15