update attempt

This commit is contained in:
Ivan Grachyov
2025-05-11 01:58:58 +03:00
parent 14ab069846
commit ae5133bd87
4 changed files with 75 additions and 27 deletions

View File

@@ -112,16 +112,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

View File

@@ -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)
@@ -22,6 +22,8 @@ function Wheel:initialize(vehicle, name, config)
self.rotationAxle = config.RotationAxle or Angle(0, 0, 1)
self.direction = math.sign(math.cos(math.rad(config.Offset or 0)))
self.wireInputs = {
[self.name] = 'entity'
}
@@ -51,9 +53,9 @@ function Wheel:initialize(vehicle, name, config)
self.holo = self:createHolo(self.entity)
if DEBUG then
self.debugHoloF:setPos(self.entity:getPos())
self.debugHoloR:setPos(self.entity:getPos())
self.debugHoloU:setPos(self.entity:getPos())
self.debugHoloF:setPos(self.entity:localToWorld(Vector(24,0,0)))
self.debugHoloR:setPos(self.entity:localToWorld(Vector(0,24,0)))
self.debugHoloU:setPos(self.entity:localToWorld(Vector(0,0,0)))
self.debugHoloF:setParent(self.entity)
self.debugHoloR:setParent(self.entity)
@@ -128,15 +130,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
@@ -153,7 +152,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)