Vehicles/VehicleScripts/CylinderAnimator.lua

CylinderAnimator initializes cylinders from lua. You can also achieve the same effect by adding the LuaCylinder component to the object via Modding SDK.

The script needs three indexes:

  1. cylinderIndex specifies the cylinder. It will always be rotated in such way that its Z axis hits the target.
  2. targetIndex specifies the target.
  3. pistonIndex represents the piston. This should be a child object of the cylinder. Its pivot will be placed exactly to the target.

In many use cases, the cylinder will be the child of some stationary part (e.g. the body of a snowcat). On the other hand, the target will be child of some moving part (e.g. the snowcat's groomer or blade). CylinderAnimator ensures that the cylinder will always be connected to the target.

For performance reasons, the actual runtime calculations are done via C#. If necessary, you can view the source code in the Modding SDK.

  35  CylinderAnimator                    = CylinderAnimator or {};

CylinderAnimator:load(dataTable)

This sets up the LuaCylinder component for each cylinder in the data table.

  39  function CylinderAnimator:load(dataTable)
  40      self.cylinders                  = {};
  41  
  42      if dataTable.cylinders ~= nil then
  43          for k, v in pairs(dataTable.cylinders) do
  44              local id                = getChild(self.id, v.cylinder or v.cylinderIndex or "");
  45  
  46              if id ~= nil then
  47                  local cylinder      = {};
  48                  cylinder.cylinderId = id;
  49                  cylinder.targetId   = getChild(self.id, v.target or v.targetIndex or "");
  50  
  51                  if v.piston == nil or v.piston == "" then
  52                      -- update by C#
  53                      Cylinder.new(cylinder.cylinderId, cylinder.targetId);
  54                  else 
  55                      cylinder.pistonId   = getChild(self.id, v.piston or v.pistonIndex or "");
  56                      -- update by C#
  57                      Cylinder.new(cylinder.cylinderId, cylinder.targetId, cylinder.pistonId);
  58                  end;
  59                  
  60                  table.insert(self.cylinders, cylinder);
  61              end;
  62          end;
  63      end;
  64  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.