addTrackedVehicleById
Definition
-- @/lua/ge/extensions/gameplay/util/crashDetection.lua:633
local function addTrackedVehicleById(vehId_, crashSettings, owner)
if vehId_ == nil or vehId_ < 0 then
--log('W', 'crashDetection', "Cannot add a vehicle with a nil or negative ID")
return
end
local vehMapObject = map.objects[vehId_]
if not vehMapObject then
--log('W', 'crashDetection', "Didn't find vehicle with id " .. vehId_)
return
end
-- can make the crash detection more sensitive by tweaking these values
local crashSettings = crashSettings or {}
crashSettings.minAccel = 0
crashSettings.maxAccel = crashSettings.maxAccel or 100
crashSettings.minDamage = 150
crashSettings.maxDamage = crashSettings.maxDamage or 5000
crashSettings.verticallyUnweighted = crashSettings.verticallyUnweighted or false
crashSettings.minVelocity = crashSettings.minVelocity or 1
crashSettings.groupImpactsDist = math.max(0.1, crashSettings.groupImpactsDist or 1)
crashSettings.enableImpactLocationData = crashSettings.enableImpactLocationData or false
trackedVehIds[vehId_] = {
debug = {
histories = {
jerk = {graphNumber = 2, color = {0.1, 0.5, 1, 1}, name = "Accel Jerk", data = {}},
accel = {graphNumber = 1,color = {0.2, 1, 0.1, 1}, name = "Accel", data = {}},
accelVerticallyUnweighted = {graphNumber = 1, color = {1, 0.1, 0.1, 1}, name = "Accel Vertically Unweighted (Road bump removal)", data = {}},
threshold = {graphNumber = 3, color = {0.2, 1, 0.1, 1}, name = "Damage Threshold to detect impact. Goes down with acceleration", data = {}},
damage = {graphNumber = 3, color = {1, 0.1, 0.1, 1}, name = "Impact Damage. If exceeds threshold, impact is detected", data = {}},
crashStarted = {graphNumber = 4, color = {0, 0, 1, 1}, name = "Crash Started", data = {}},
crashEnded = {graphNumber = 4, color = {1, 1, 1, 1}, name = "Crash Ended", data = {}},
impactStarted = {graphNumber = 4, color = {0, 1, 0, 1}, name = "Impact Started", data = {}},
impactEnded = {graphNumber = 4, color = {1, 0, 0, 1}, name = "Impact Ended", data = {}},
},
eventFlags = {
crashStarted = false,
crashEnded = false,
impactStarted = false,
impactEnded = false,
},
graphEnabled = {
[1] = im.BoolPtr(false), -- Acceleration graphs
[2] = im.BoolPtr(false), -- Jerk graph
[3] = im.BoolPtr(true), -- Threshold/Damage graphs
[4] = im.BoolPtr(false), -- Event graphs
}
},
--currentCrashImpacts = {
-- (impacts) {},{},{},{},{},
--},
--preImpactData = {}, -- because there is a minimum damage threshold to what is considered an impact, and that we want accurate data about the starting conditions (position, speed..)
totalCrashTime = 0,
vehId = vehId_,
owner = owner or "unknown",
crashSettings = crashSettings,
lastFrameDamage = vehMapObject.damage or 0,
lastFrameDamageSum = scenetree.findObjectById(vehId_):getSectionDamageSum() or 0,
totalPreImpactDamage = 0,
totalCurrentImpactDamage = 0,
mightBeCrashing = false,
isCrashing = false,
accelData = {
front = {
offsetFromCenter = 4, -- arbitrary offset from the center of the vehicle
lastFrameVel = vec3(),
lastFramePos = vec3(),
vel = vec3(),
},
rear = {
offsetFromCenter = -4, -- arbitrary offset from the center of the vehicle
lastFrameVel = vec3(),
lastFramePos = vec3(),
vel = vec3(),
}
}
}
end
Callers
@/lua/ge/extensions/gameplay/crashTest/scenarioManager.lua
end
gameplay_util_crashDetection.addTrackedVehicleById(vehId, crashDetectionSettings, "crashAnalysis");
end
@/lua/ge/extensions/flowgraph/nodes/gameplay/crash/trackMultipleVehiclesCrash.lua
for _, vehId in ipairs(self.pinIn.vehIds.value) do
gameplay_util_crashDetection.addTrackedVehicleById(vehId);
end
@/lua/ge/extensions/flowgraph/nodes/gameplay/crash/trackVehicleCrash.lua
function C:work()
gameplay_util_crashDetection.addTrackedVehicleById(self.pinIn.vehId.value);
end
@/lua/ge/extensions/gameplay/drift/drift.lua
if vehId ~= nil and gameplay_drift_general.getContext() ~= "inAnotherMissionType" and not gameplay_util_crashDetection.isVehTracked(vehId) and vehId > -1 then
gameplay_util_crashDetection.addTrackedVehicleById(vehId, crashDetectionSettings, "drift")
end