meta data for this page
Vehicles/VehicleScripts/PrinothSteering.lua
This script is concepted for the Prinoth Leitwolf. It controlls the alignment of the “steering wheel” levers refering to the current speed.
25 PrinothSteering = PrinothSteering or {};
PrinothSteering:load(dataTable)
Loading of Datatable.
29 function PrinothSteering:load(dataTable) 30 31 if dataTable.PrinothSteering ~= nil then 32 self.crawlerSpeederLeft = getChild(self.id, dataTable.PrinothSteering.crawlerSpeederIndexLeft); 33 self.crawlerSpeederRight = getChild(self.id, dataTable.PrinothSteering.crawlerSpeederIndexRight); 34 self.maxThrottleAngle = dataTable.PrinothSteering.maxThrottleAngle; 35 self.steeringWheelAngle = dataTable.PrinothSteering.steeringWheelAngle; 36 self.steeringWheelAxle = dataTable.PrinothSteering.steeringWheelAxle; 37 if dataTable.PrinothSteering.steeringPointLeft ~= nil and dataTable.PrinothSteering.steeringPointRight ~= nil and dataTable.PrinothSteering.steeringHandIkTarget ~= nil then 38 self.steeringPointLeft = getChild(self.id, dataTable.PrinothSteering.steeringPointLeft); 39 self.steeringPointRight = getChild(self.id, dataTable.PrinothSteering.steeringPointRight); 40 self.steeringHandIkTarget = getChild(self.id, dataTable.PrinothSteering.steeringHandIkTarget); 41 end; 42 end; 43 44 self.lerpValueForward = 0; 45 self.lerpValueDirection = 0; 46 self.maxSpeed = dataTable.maxSpeed or 40; 47 end; 48 49 -- updates the position of the "steering wheel" levers 50 function PrinothSteering:update(dt) 51 if not self:getIsActive() then 52 return; 53 end; 54 55 local steerValue = self.steerValue; 56 self.lerpValueForward = lerp(0, self.steeringWheelAngle, self.currentSpeed / self.maxSpeed); 57 self.lerpValueDirection = lerp(self.lerpValueDirection, self.maxThrottleAngle * steerValue * self.currentSpeed / self.maxSpeed, dt * 10); 58 59 setRotationX(self.crawlerSpeederLeft, math.min(self.steeringWheelAngle, self.lerpValueForward + self.lerpValueDirection)); 60 setRotationX(self.crawlerSpeederRight, math.min(self.steeringWheelAngle, self.lerpValueForward - self.lerpValueDirection)); 61 62 if self.steeringWheelAxle == 1 then 63 setRotationX(self.crawlerSpeederLeft, math.min(self.steeringWheelAngle, self.lerpValueForward + self.lerpValueDirection)); 64 setRotationX(self.crawlerSpeederRight, math.min(self.steeringWheelAngle, self.lerpValueForward - self.lerpValueDirection)); 65 66 elseif self.steeringWheelAxle == 2 then 67 setRotationY(self.crawlerSpeederLeft, math.min(self.steeringWheelAngle, self.lerpValueForward + self.lerpValueDirection)); 68 setRotationY(self.crawlerSpeederRight, math.min(self.steeringWheelAngle, self.lerpValueForward - self.lerpValueDirection)); 69 70 else 71 setRotationZ(self.crawlerSpeederLeft, math.min(self.steeringWheelAngle, self.lerpValueForward + self.lerpValueDirection)); 72 setRotationZ(self.crawlerSpeederRight, math.min(self.steeringWheelAngle, self.lerpValueForward - self.lerpValueDirection)); 73 end; 74 75 if self.steeringPointLeft ~= nil and self.steeringPointRight ~= nil and self.steeringHandIkTarget ~= nil then 76 local xLeft, yLeft, zLeft = getWorldPosition(self.steeringPointLeft); 77 local xRight, yRight, zRight = getWorldPosition(self.steeringPointRight); 78 79 local xAvg = (xLeft + xRight)/2; 80 local yAvg = (yLeft + yRight)/2; 81 local zAvg = (zLeft + zRight)/2; 82 83 setWorldPosition(self.steeringHandIkTarget, xAvg, yAvg, zAvg); 84 85 local rxPointLeft, ryPointLeft, rzPointLeft = getWorldRotation(self.steeringPointLeft); 86 local rxPointRight, ryPointRight, rzPointRight = getWorldRotation(self.steeringPointRight); 87 if rxPointLeft > 180 then 88 rxPointLeft = rxPointLeft - 360; 89 end; 90 91 if rxPointRight > 180 then 92 rxPointRight = rxPointRight - 360; 93 end; 94 local handRot = rxPointLeft - rxPointRight; 95 setRotation(self.steeringHandIkTarget, (rxPointLeft + rxPointRight)/2/2, (handRot), 0); 96 end; 97 end;
Copyright
All contents of this page may be used for modding use for Winter Resort Simulator - Season 2 only. Any use exceeding this regulation is not permitted.
Copyright (C) HR Innoways, 2021. All Rights Reserved.