LUADOC - Farming Simulator 17

Printable Version

WheelRotations

Description
Class for wheel rotations
Functions

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
20function WheelRotations:load(savegame)
21
22 self.wheelRotations = {};
23 local i=0;
24 while true do
25 local baseName = string.format("vehicle.wheelRotations.wheelRotation(%d)", i);
26 if not hasXMLProperty(self.xmlFile, baseName) then
27 break;
28 end;
29
30 local node = Utils.indexToObject(self.components, getXMLString(self.xmlFile, baseName.."#index"));
31 local wheelIndex = getXMLInt(self.xmlFile, baseName.."#wheelIndex");
32 if node ~= nil and self.wheels[wheelIndex+1] ~= nil then
33 table.insert(self.wheelRotations, {node=node, wheel=self.wheels[wheelIndex+1]});
34 end;
35 i = i + 1;
36 end;
37
38 for _, wheel in ipairs(self.wheels) do
39 local wheelnamei = string.format("vehicle.wheels.wheel(%d)", wheel.xmlIndex);
40 if hasXMLProperty(self.xmlFile, wheelnamei .. "#rotSpeedLimit") then
41 wheel.rotSpeedLimit = getXMLInt(self.xmlFile, wheelnamei.."#rotSpeedLimit");
42 wheel.rotSpeedDefault = wheel.rotSpeed;
43 wheel.rotSpeedNegDefault = wheel.rotSpeedNeg;
44 wheel.currentRotSpeedAlpha = 1;
45 end;
46 end;
47end;

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
61function WheelRotations:update(dt)
62 if self:getIsActive() and self.firstTimeRun then
63 for _, wheelRotation in pairs(self.wheelRotations) do
64 local _,y,_ = getRotation(wheelRotation.wheel.repr);
65 setRotation(wheelRotation.node, 0, y, 0);
66 end;
67 end;
68end;

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
73function WheelRotations:updateTick(dt)
74 if self:getIsActive() then
75 for _, wheel in pairs(self.wheels) do
76 if wheel.rotSpeedLimit ~= nil then
77 local dir = -1;
78 if self:getLastSpeed() <= wheel.rotSpeedLimit then
79 dir = 1;
80 end;
81 wheel.currentRotSpeedAlpha = Utils.clamp(wheel.currentRotSpeedAlpha + dir*(dt/1000), 0, 1)
82 wheel.rotSpeed = wheel.rotSpeedDefault * wheel.currentRotSpeedAlpha;
83 wheel.rotSpeedNeg = wheel.rotSpeedNegDefault * wheel.currentRotSpeedAlpha;
84 end;
85 end;
86 end;
87end;