update attempt
This commit is contained in:
parent
14ab069846
commit
ae5133bd87
@ -7,13 +7,49 @@
|
|||||||
local Vehicle, POWERTRAIN_COMPONENT = unpack(require('/koptilnya/engine_remastered/vehicle.txt'))
|
local Vehicle, POWERTRAIN_COMPONENT = unpack(require('/koptilnya/engine_remastered/vehicle.txt'))
|
||||||
local Differential = require('/koptilnya/engine_remastered/powertrain/differential.txt')
|
local Differential = require('/koptilnya/engine_remastered/powertrain/differential.txt')
|
||||||
|
|
||||||
|
-- Michelin Pilot Sport 4S (High-Performance Road Tire)
|
||||||
local WheelConfig = {
|
local WheelConfig = {
|
||||||
BrakePower = 1200,
|
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'
|
Model = 'models/sprops/trans/wheel_a/wheel25.mdl'
|
||||||
}
|
}
|
||||||
local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 33, CustomWheel = { CasterAngle = 3 } })
|
local FrontWheelsConfig = table.merge(
|
||||||
local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2200 })
|
table.copy(WheelConfig),
|
||||||
|
{
|
||||||
|
SteerLock = 33,
|
||||||
|
CustomWheel = {
|
||||||
|
CasterAngle = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
local RearWheelsConfig = table.merge(
|
||||||
|
table.copy(WheelConfig),
|
||||||
|
{
|
||||||
|
HandbrakePower = 2200
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Vehicle:new({
|
Vehicle:new({
|
||||||
{
|
{
|
||||||
@ -77,13 +113,13 @@ Vehicle:new({
|
|||||||
Name = 'WheelFL',
|
Name = 'WheelFL',
|
||||||
Type = POWERTRAIN_COMPONENT.Wheel,
|
Type = POWERTRAIN_COMPONENT.Wheel,
|
||||||
Input = 'AxleFront',
|
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',
|
Name = 'WheelFR',
|
||||||
Type = POWERTRAIN_COMPONENT.Wheel,
|
Type = POWERTRAIN_COMPONENT.Wheel,
|
||||||
Input = 'AxleFront',
|
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',
|
Name = 'AxleBack',
|
||||||
@ -119,12 +155,12 @@ Vehicle:new({
|
|||||||
Name = 'WheelRL',
|
Name = 'WheelRL',
|
||||||
Input = 'AxleBack',
|
Input = 'AxleBack',
|
||||||
Type = POWERTRAIN_COMPONENT.Wheel,
|
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',
|
Name = 'WheelRR',
|
||||||
Input = 'AxleBack',
|
Input = 'AxleBack',
|
||||||
Type = POWERTRAIN_COMPONENT.Wheel,
|
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 } })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -112,16 +112,27 @@ function Differential:forwardStep(torque, inertia)
|
|||||||
-- // REFACTOR
|
-- // REFACTOR
|
||||||
if self.steerLock ~= 0 then
|
if self.steerLock ~= 0 then
|
||||||
local steerInertia = (aI + bI) / 2
|
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 maxSteerSpeed = math.rad(1337)
|
||||||
|
|
||||||
local inputTorque = self.vehicle.steer * inputForce
|
local inputTorque = self.vehicle.steer * inputForce
|
||||||
|
|
||||||
local avgSteerAngle = (self.outputA.customWheel.steerAngle + self.outputB.customWheel.steerAngle) / 2
|
local avgSteerAngle = (self.outputA.customWheel.steerAngle + self.outputB.customWheel.steerAngle) / 2
|
||||||
local mz = self.outputA.customWheel.mz + self.outputB.customWheel.mz
|
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 avgMz = (self.outputA.customWheel.mz + self.outputB.customWheel.mz) / 2
|
||||||
local maxMz = math.max(self.outputA.customWheel.mz + self.outputB.customWheel.mz)
|
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
|
local steerAngularAccel = steerTorque / steerInertia
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ require('/koptilnya/libs/entity.txt')
|
|||||||
|
|
||||||
local Wheel = class('Wheel', PowertrainComponent)
|
local Wheel = class('Wheel', PowertrainComponent)
|
||||||
|
|
||||||
local DEBUG = false
|
local DEBUG = true
|
||||||
|
|
||||||
function Wheel:initialize(vehicle, name, config)
|
function Wheel:initialize(vehicle, name, config)
|
||||||
PowertrainComponent.initialize(self, vehicle, name, config)
|
PowertrainComponent.initialize(self, vehicle, name, config)
|
||||||
@ -22,6 +22,8 @@ function Wheel:initialize(vehicle, name, config)
|
|||||||
|
|
||||||
self.rotationAxle = config.RotationAxle or Angle(0, 0, 1)
|
self.rotationAxle = config.RotationAxle or Angle(0, 0, 1)
|
||||||
|
|
||||||
|
self.direction = math.sign(math.cos(math.rad(config.Offset or 0)))
|
||||||
|
|
||||||
self.wireInputs = {
|
self.wireInputs = {
|
||||||
[self.name] = 'entity'
|
[self.name] = 'entity'
|
||||||
}
|
}
|
||||||
@ -51,9 +53,9 @@ function Wheel:initialize(vehicle, name, config)
|
|||||||
self.holo = self:createHolo(self.entity)
|
self.holo = self:createHolo(self.entity)
|
||||||
|
|
||||||
if DEBUG then
|
if DEBUG then
|
||||||
self.debugHoloF:setPos(self.entity:getPos())
|
self.debugHoloF:setPos(self.entity:localToWorld(Vector(24,0,0)))
|
||||||
self.debugHoloR:setPos(self.entity:getPos())
|
self.debugHoloR:setPos(self.entity:localToWorld(Vector(0,24,0)))
|
||||||
self.debugHoloU:setPos(self.entity:getPos())
|
self.debugHoloU:setPos(self.entity:localToWorld(Vector(0,0,0)))
|
||||||
|
|
||||||
self.debugHoloF:setParent(self.entity)
|
self.debugHoloF:setParent(self.entity)
|
||||||
self.debugHoloR:setParent(self.entity)
|
self.debugHoloR:setParent(self.entity)
|
||||||
@ -128,15 +130,12 @@ function Wheel:forwardStep(torque, inertia)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print(inertia)
|
self.customWheel.motorTorque = torque * self.direction
|
||||||
-- self.customWheel:setInertia(inertia)
|
|
||||||
|
|
||||||
self.customWheel.motorTorque = torque
|
|
||||||
self.customWheel.brakeTorque = math.max(self.brakePower * self.vehicle.brake, self.handbrakePower * self.vehicle.handbrake)
|
self.customWheel.brakeTorque = math.max(self.brakePower * self.vehicle.brake, self.handbrakePower * self.vehicle.handbrake)
|
||||||
|
|
||||||
self.customWheel:update()
|
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
|
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
|
local surfaceForceVector = self.customWheel.right * self.customWheel.sideFriction.force + self.customWheel.forward * self.customWheel.forwardFriction.force
|
||||||
@ -153,7 +152,7 @@ function Wheel:forwardStep(torque, inertia)
|
|||||||
|
|
||||||
local entityAngles = self.entity:getAngles()
|
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 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)
|
local camberRotated = steerRotated:rotateAroundAxis(self.customWheel.forward, nil, -self.customWheel.camberAngle)
|
||||||
|
|||||||
@ -23,8 +23,10 @@ function Wheel:initialize(config)
|
|||||||
|
|
||||||
self.forwardFriction = Friction:new(config.ForwardFriction)
|
self.forwardFriction = Friction:new(config.ForwardFriction)
|
||||||
self.sideFriction = Friction:new(config.SideFriction)
|
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.motorTorque = 0
|
||||||
self.brakeTorque = 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)
|
Tb = math.clamp(Tb, -TbCap, TbCap)
|
||||||
W = W + Tb / I * TICK_INTERVAL
|
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 errorTorque = (W - Vx / R) * I / TICK_INTERVAL
|
||||||
local surfaceTorque = math.clamp(errorTorque, -maxTorque, maxTorque)
|
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 = Sy * kSy * 0.95
|
||||||
Sy = math.clamp(Sy, -1, 1)
|
Sy = math.clamp(Sy, -1, 1)
|
||||||
local slipSign = Sy < 0 and -1 or 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
|
if Lc < 0.0001 then
|
||||||
Sy = 0
|
Sy = 0
|
||||||
@ -178,10 +180,10 @@ function Wheel:selfAligningTorque(Sy, load)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local B = self.satFrictionPreset.B
|
local B = self.aligningFrictionPreset.B
|
||||||
local C = self.satFrictionPreset.C
|
local C = self.aligningFrictionPreset.C
|
||||||
local D = self.satFrictionPreset.D
|
local D = self.aligningFrictionPreset.D
|
||||||
local E = self.satFrictionPreset.E
|
local E = self.aligningFrictionPreset.E
|
||||||
|
|
||||||
local loadScale = load * 1000
|
local loadScale = load * 1000
|
||||||
local mechanicalTrail = 0.15
|
local mechanicalTrail = 0.15
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user