isCrashAvoidable
Definition
-- @/lua/ge/map.lua:3686
local function isCrashAvoidable(objectID, pos, radius)
-- check if position (pos) with dimension radius is safe to spawn given object (objectID) in motion
local obj = getObjectByID(objectID)
if not obj then return true end
radius = radius or 7.5
local relativePos = pos - vec3(obj:getSpawnWorldOOBB():getCenter())
local relativePosLen = relativePos:length()
-- Over 150m, we assume it's safe to spawn
if relativePosLen > 150 then return true end
local objVel = vec3(obj:getVelocity())
local relativeSpeed = max(objVel:dot(relativePos / (relativePosLen + 1e-30)), 0)
local ff = 0.5 * vecUp:dot(vec3(obj:getDirectionVectorUp())) -- frictionCoeff * Normal Force.
local objDirVec = vec3(obj:getDirectionVector())
local fw = vecUp:dot(sign(objVel:dot(objDirVec)) * objDirVec) -- road grade force
-- Prevents division by zero gravity
local gravity = core_environment.getGravity()
gravity = max(0.1, abs(gravity)) * sign2(gravity)
local a = max(1e-30, -gravity * (ff + fw))
return relativePosLen > relativeSpeed * relativeSpeed / (2 * a) + obj:getInitialLength() * 0.5 + radius
end
Callers
@/lua/ge/spawn.lua
for _, otherId in ipairs(gameplay_traffic.getTrafficList()) do
if otherId ~= vehID and (not map.isCrashAvoidable(otherId, bbCenter, vehRadius) or intersectingOtherVehicle(getObjectByID(otherId), axis0, axis1, axis2, halfExtentsX, halfExtentsY, halfExtentsZ, bbCenter)) then
gameplay_traffic.forceTeleport(otherId, bbCenter)