Added wheels rotation; config for model and offset requires fixing

This commit is contained in:
Ivan Grachyov 2023-05-22 21:14:00 +03:00
parent 9fb68001f1
commit aa596db8b7
2 changed files with 19 additions and 13 deletions

View File

@ -8,7 +8,9 @@ local Vehicle, POWERTRAIN_COMPONENT = unpack(require('/koptilnya/engine_remaster
local WheelConfig = { local WheelConfig = {
BrakePower = 800, BrakePower = 800,
CustomWheel = {} CustomWheel = {},
Offset = 90,
Model = 'models/sprops/trans/wheel_d/t_wheel25.mdl'
} }
local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 10 }) local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 10 })
local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2000 }) local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2000 })

View File

@ -24,11 +24,15 @@ function Wheel:initialize(vehicle, name, config)
self.wireOutputs = { self.wireOutputs = {
[string.format('%s_RPM', self.name)] = 'number', [string.format('%s_RPM', self.name)] = 'number',
[string.format('%s_Mz', self.name)] = 'number', [string.format('%s_Mz', self.name)] = 'number',
[string.format('%s_Fz', self.name)] = 'number' [string.format('%s_Fz', self.name)] = 'number',
} }
self.rot = 0
self.offset = config.Offset or 0
self.entity = config.Entity or NULL_ENTITY self.entity = config.Entity or NULL_ENTITY
self.holo = self:createHolo(self.entity)
self.holo = self:createHolo(self.entity, config.Model or 'models/sprops/trans/wheel_b/t_wheel15.mdl', self.offset)
self.customWheel = CustomWheel:new(config.CustomWheel) self.customWheel = CustomWheel:new(config.CustomWheel)
@ -58,14 +62,18 @@ function Wheel:getEntityRadius()
return self.entity:getModelRadius() * UNITS_TO_METERS return self.entity:getModelRadius() * UNITS_TO_METERS
end end
function Wheel:createHolo(entity) function Wheel:createHolo(entity, model, offset)
if not isValid(entity) then if not isValid(entity) then
return NULL_ENTITY return NULL_ENTITY
end end
local holo = holograms.create(entity:getPos(), entity:getAngles(), 'models/props_c17/pulleywheels_small01.mdl') print(model)
local holo = holograms.create(entity:getPos(), entity:getAngles() + Angle(0, offset, 0), model)
holo:setParent(entity) holo:setParent(entity)
entity:setColor(Color(0,0,0,0))
return holo return holo
end end
@ -105,15 +113,11 @@ function Wheel:forwardStep(torque, inertia)
end end
if isValid(self.holo) then if isValid(self.holo) then
local angles = self.holo:getAngles() self.rot = self.rot + math.deg(self.angularVelocity) * TICK_INTERVAL
--local rot = angles:rotateAroundAxis(self.entity:getForward(), nil, 1)
local rot = angles:rotateAroundAxis(self.entity:getRight(), nil, -self.angularVelocity * TICK_INTERVAL)
--local steer = Angle():rotateAroundAxis(self.entity:getUp(), self.customWheel.steerAngle)
--local rot = self.entity:getRight():getQuaternionFromAxis(-self.angularVelocity * TICK_INTERVAL)
--local steer = self.entity:getUp():getQuaternionFromAxis(self.steerAngle)
--self.holo:setAngles(self.entity:localToWorldAngles(Angle(0, 90 - self.customWheel.steerAngle, 0))) local angle = self.entity:localToWorldAngles(Angle(0, self.offset - self.customWheel.steerAngle, self.rot))
self.holo:setAngles(rot)
self.holo:setAngles(angle)
end end
return self.customWheel.counterTorque return self.customWheel.counterTorque