Script v1.4.4.0
- Handtools
- Events
- Objects
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BuiltInCutterTrailer
- BunkerSiloCompacter
- Combine
- ConveyorBelt
- Cover
- CrabSteering
- Crawler
- Cultivator
- Cutter
- Cylindered
- Drivable
- DynamicMountAttacher
- Fillable
- FillActivatable
- FillVolume
- Foldable
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- FuelTrailer
- Honk
- HookLiftContainer
- HookLiftTrailer
- Leveler
- Lights
- LivestockTrailer
- ManureBarrel
- ManureSpreader
- MixerWagon
- Motorized
- Mountable
- Mower
- NonTabbable
- Overloading
- Pickup
- Pipe
- Plough
- PowerConsumer
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- RidgeMarker
- Roller
- Ropes
- RotorSpreader
- SemiTrailerFront
- Shovel
- SowingMachine
- SpeedRotatingParts
- Sprayer
- Steerable
- StrawBlower
- StumpCutter
- Tedder
- TensionBelts
- Trailer
- TreePlanter
- TreePlanterActivatable
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Weeder
- WheelRotations
- Windrower
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkParticles
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
WheelRotations
DescriptionClass for wheel rotationsFunctions
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
20 | function 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; |
47 | end; |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
61 | function 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; |
68 | end; |
updateTick
DescriptionCalled on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
73 | function 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; |
87 | end; |