Vehicles/VehicleScripts/CylinderSpring.lua

The cylinder spring script animates a spring that is part of a CylinderAnimator. It is initialized via the same entry in the data table.

  25  CylinderSpring                  = CylinderSpring or {};

CylinderSpring:load(dataTable)

This sets up cylinder spring and the target position in the data table.

  29  function CylinderSpring:load(dataTable)
  30      self.cylinderSprings                = {};
  31  
  32      if dataTable.cylinders ~= nil then
  33          for k, v in pairs(dataTable.cylinders) do
  34              if v.cylinderSpring ~= nil and v.cylinderSpring ~= "" then
  35                  local cylinderSpring            = {};
  36                  cylinderSpring.spring           = getChild(self.id, v.cylinderSpring);
  37                  cylinderSpring.springTarget     = getChild(self.id, v.cylinderSpringTarget);
  38  
  39                  -- get location of spring
  40                  local springX, springY, springZ = getWorldPosition(cylinderSpring.spring);
  41  
  42                  -- get location of springTarget
  43                  local targetX, targetY, targetZ = getWorldPosition(cylinderSpring.springTarget);
  44  
  45                  cylinderSpring.defaultDistance  = Vector3:new(springX, springY, springZ):distanceTo(Vector3:new(targetX, targetY, targetZ));
  46  
  47                  table.insert(self.cylinderSprings, cylinderSpring);
  48              end;
  49          end;
  50      end;
  51      if dataTable.sounds ~= nil and dataTable.sounds.suspensionThumb ~= nil then
  52          self.suspensionSound                            = self:loadSingleSound(dataTable.sounds.suspensionThumb);
  53      end;
  54  end;

CylinderSpring:update(dt)

Update the cylinder spring squish factor.

  58  function CylinderSpring:update(dt)
  59      for k,spring in pairs(self.cylinderSprings) do
  60          -- get location of spring
  61          local springX, springY, springZ         = getWorldPosition(spring.spring);
  62  
  63          -- get location of springTarget
  64          local targetX, targetY, targetZ         = getWorldPosition(spring.springTarget);
  65  
  66          -- calculate difference
  67          local distance                          = Vector3:new(springX, springY, springZ):distanceTo(Vector3:new(targetX, targetY, targetZ));
  68          
  69          -- calculate the squish factor
  70          local squishFactor                      = distance / spring.defaultDistance;
  71          
  72          setScale(spring.spring, 1, squishFactor, 1);
  73      end;
  74  end;

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.