GE Lua Documentation

Press F to search!

spawnPhysicsForVehicle

Definition


-- @/lua/ge/extensions/core/vehicle/manager.lua:68

local function spawnPhysicsForVehicle(objID, vehicleObj, vehicleBundle)
  if not objID then
    objID = be:getPlayerVehicleID(0)
  end
  local _vehicleBundle = vehicleBundle or vehicles[objID]
  if not vehicleObj or not _vehicleBundle then
    vehicleObj = scenetree.findObject(objID)
    if not vehicleObj then return end
  end

  if not _vehicleBundle or not _vehicleBundle.vdata then
    -- send an empty vehicle bundle to the physics engine to avoid stale data
    _vehicleBundle = {vdata = {}, config = {}}
  end

  profilerPushEvent('serialize')
  -- do not send everything, filter some UI things that are not required
  local vehicleBundleDataString = lpack.encode({
    vdata  = _vehicleBundle.vdata,
    config = _vehicleBundle.config,
  })
  profilerPopEvent('serialize')

  local luaVMType = 0 -- 0 = vehicle, 1 = object pool, 2 = none

  profilerPushEvent('spawnPhysics')
  vehicleObj:spawnPhysics(vehicleBundleDataString or '', luaVMType)
  profilerPopEvent('spawnPhysics')
end

Callers

@/lua/ge/extensions/core/vehicle/manager.lua
  if spawnPhysics then
    spawnPhysicsForVehicle(objID, vehicleObj, vehicleBundle)
  end