-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt

local M = {}
local lastZ = 0

local function onInit()
	electrics.values['vsi_feetPerMinute'] = 0
  lastZ = obj:getPosition().z
end

local function onReset()
	onInit()
end

local function updateGFX(dt)
  local curPos = obj:getPosition()
  
	local metersPerSecond = (lastZ - curPos.z) / dt
	electrics.values['vsi_feetPerMinute'] = metersPerSecond * -196.850394
  
  lastZ = curPos.z
end

-- public interface
M.onInit      = onInit
M.onReset     = onReset
M.updateGFX = updateGFX

return M