update
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
--@include /koptilnya/libs/constants.txt
|
||||
--@include ./powertrain_component.txt
|
||||
|
||||
|
||||
local PowertrainComponent = require('./powertrain_component.txt')
|
||||
local WheelComponent = require('./wheel.txt')
|
||||
|
||||
@@ -29,6 +28,9 @@ function Differential:initialize(vehicle, name, config)
|
||||
self.stiffness = config.Stiffness or 0.1
|
||||
self.slipTorque = config.SlipTorque or 1000
|
||||
self.splitStrategy = Differential.getSplitStrategy(config.Type or Differential.TYPES.Open)
|
||||
|
||||
self.steerLock = config.SteerLock or 0
|
||||
self.steerAngle = 0
|
||||
end
|
||||
|
||||
function Differential:linkComponent(component)
|
||||
@@ -107,6 +109,40 @@ function Differential:forwardStep(torque, inertia)
|
||||
tqA = self.outputA:forwardStep(tqA, inertia * 0.5 * math.pow(self.finalDrive, 2) + aI) / self.finalDrive
|
||||
tqB = self.outputB:forwardStep(tqB, inertia * 0.5 * math.pow(self.finalDrive, 2) + bI) / self.finalDrive
|
||||
|
||||
-- // REFACTOR
|
||||
if self.steerLock ~= 0 then
|
||||
local steerInertia = (aI + bI) / 2
|
||||
local inputForce = 228.0
|
||||
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 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 steerAngularAccel = steerTorque / steerInertia
|
||||
|
||||
self.steerAngle = math.clamp(
|
||||
self.steerAngle + steerAngularAccel * TICK_INTERVAL,
|
||||
-self.steerLock,
|
||||
self.steerLock
|
||||
)
|
||||
|
||||
-- Аккерман
|
||||
local wheelbase = 2.05
|
||||
local trackWidth = 1.124
|
||||
local radius = wheelbase / math.tan(math.rad(self.steerAngle))
|
||||
|
||||
local innerAngle = math.deg(math.atan(wheelbase / (radius - (trackWidth / 2))))
|
||||
local outerAngle = math.deg(math.atan(wheelbase / (radius + (trackWidth / 2))))
|
||||
|
||||
self.outputA.customWheel.steerAngle = outerAngle
|
||||
self.outputB.customWheel.steerAngle = innerAngle
|
||||
end
|
||||
|
||||
return (tqA + tqB) / self.finalDrive
|
||||
end
|
||||
|
||||
|
||||
@@ -55,10 +55,24 @@ function Wheel:initialize(vehicle, name, config)
|
||||
end
|
||||
end)
|
||||
|
||||
local right = self.entity:getRight()
|
||||
local right = self.entity:getRight():getRotated(Angle(0, 90, 0))
|
||||
local offsetRight = self.entity:getRight():rotateAroundAxis(self.entity:getUp(), self.offset)
|
||||
|
||||
self.dir = right:dot(offsetRight)
|
||||
|
||||
self.debugHolo1 = holograms.create(
|
||||
Vector(),
|
||||
Angle(),
|
||||
'models/sprops/geometry/sphere_3.mdl'
|
||||
)
|
||||
|
||||
self.debugHolo2 = holograms.create(
|
||||
Vector(),
|
||||
Angle(),
|
||||
'models/sprops/geometry/sphere_3.mdl'
|
||||
)
|
||||
|
||||
self.steerVelocity = 0
|
||||
end
|
||||
|
||||
function Wheel:getEntityRadius()
|
||||
@@ -79,8 +93,10 @@ function Wheel:createHolo(entity)
|
||||
entity:getAngles() + Angle(0, self.offset, 0),
|
||||
self.CONFIG.Model or ''
|
||||
)
|
||||
|
||||
holo:setParent(entity)
|
||||
|
||||
-- holo:setColor(Color(255,255,255,110))
|
||||
entity:setColor(Color(0,0,0,0))
|
||||
|
||||
return holo
|
||||
@@ -105,7 +121,7 @@ function Wheel:forwardStep(torque, inertia)
|
||||
return 0
|
||||
end
|
||||
|
||||
self.customWheel.steerAngle = self.vehicle.steer * self.steerLock
|
||||
-- self.customWheel.steerAngle = self.vehicle.steer * self.steerLock
|
||||
--self.customWheel.inertia = inertia
|
||||
--self.customWheel:setInertia(inertia)
|
||||
self.customWheel.motorTorque = torque
|
||||
@@ -115,19 +131,39 @@ function Wheel:forwardStep(torque, inertia)
|
||||
|
||||
self.angularVelocity = self.customWheel.angularVelocity
|
||||
|
||||
self.debugHolo1:setPos(self.entity:localToWorld(Vector(0, 0, -self.entity:getModelRadius())))
|
||||
|
||||
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
|
||||
|
||||
self.vehicle.basePhysObject:applyForceOffset(surfaceForceVector, self.entity:getPos() - Vector(0, 0, self.customWheel.radius))
|
||||
self.vehicle.basePhysObject:applyForceOffset(surfaceForceVector, self.entity:localToWorld(Vector(0, 0, -self.entity:getModelRadius())))
|
||||
end
|
||||
|
||||
if isValid(self.holo) then
|
||||
self.rot = self.rot + math.deg(self.angularVelocity) * TICK_INTERVAL * self.dir
|
||||
|
||||
local steerAngle = self.entity:localToWorldAngles(Angle(0, self.offset - self.customWheel.steerAngle, 0) + self.rotationAxle * self.rot)
|
||||
local angle = steerAngle
|
||||
local spinAxis = self.customWheel.up:cross(self.customWheel.forward):getNormalized()
|
||||
|
||||
self.holo:setAngles(angle)
|
||||
self.debugHolo2:setPos(self.entity:localToWorld(self.customWheel.up * math.sin(timer.curtime()) * 20))
|
||||
|
||||
local rotatedForwardAngle = self.customWheel.forward:getAngle() + Angle(0, 90, 0)
|
||||
|
||||
|
||||
-- self.holo:setAngles(rotatedForwardAngle)
|
||||
|
||||
|
||||
-- local ang = up:getAngle()
|
||||
-- self.holo:setAngles(self.customWheel.forward:getAngle())
|
||||
|
||||
-- self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, 0))
|
||||
-- self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, nil, self.angularVelocity * TICK_INTERVAL))
|
||||
|
||||
|
||||
self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, nil, self.angularVelocity * TICK_INTERVAL))
|
||||
|
||||
-- local steerAngle = self.entity:localToWorldAngles(Angle(0, self.offset - self.customWheel.steerAngle, 0) + self.rotationAxle * self.rot)
|
||||
-- local angle = steerAngle
|
||||
|
||||
-- self.holo:setAngles(angle)
|
||||
end
|
||||
|
||||
return self.customWheel.counterTorque
|
||||
|
||||
Reference in New Issue
Block a user