checkSpawnPoint
Definition
-- @/lua/ge/extensions/gameplay/traffic/trafficUtils.lua:198
local function checkSpawnPoint(pos, origPos, minDist, minVehDist) -- checks a spawn point for any conflicts
origPos = origPos or core_camera.getPosition()
minDist = minDist or 80
minVehDist = minVehDist or 15 -- should this be based on the other vehicle size?
if pos:squaredDistance(origPos) < square(minDist) then
return false
end
local traffic = gameplay_traffic.getTrafficData()
for _, veh in ipairs(getAllVehicles()) do
if veh:getActive() then
local vehId = veh:getId()
local relSpeed = 0
if map.objects[vehId] then
tempPos:set(map.objects[vehId].pos)
tempDir:set(map.objects[vehId].vel)
tempPos:setSub2(pos, tempPos) -- actually the direction vector from the vehicle to the spawn point
tempPos:normalize()
relSpeed = clamp(tempDir:dot(tempPos), 0, 50)
local relSpeedCoef = 1.4 -- artificial coefficient, for a stricter result
local gravity = core_environment.getGravity()
relSpeed = square(relSpeed * relSpeedCoef) / (2 * math.max(0.1, math.abs(gravity)) * sign2(gravity) * -1)
end
if traffic[vehId] then
tempPos:set(traffic[vehId].pos) -- latest other traffic vehicle position
else
tempPos:set(veh:getPositionXYZ())
end
local radius = veh:isPlayerControlled() and minDist or minVehDist
if pos:squaredDistance(tempPos) < square(math.max(radius, relSpeed)) then
return false
end
end
end
return true
end
Callers
@/lua/ge/extensions/gameplay/traffic.lua
if traffic[vehId]._teleport then -- force teleport if flag exists
if gameplay_traffic_trafficUtils.checkSpawnPoint(traffic[vehId].pos) then -- if current position is safe, then no teleport needed
traffic[vehId]:onRefresh()
@/lua/ge/extensions/gameplay/traffic/trafficUtils.lua
if checkSpawnPoint(spawnData.pos, nil, minDist) then
spawnData.n1, spawnData.n2 = n1, n2
if checkSpawnPoint(spawnData.pos, nil, minDist) then
spawnData.n1, spawnData.n2 = n1, n2
if currDist >= targetDist or checkRayCast(spawnData.pos, startPos) then
if checkSpawnPoint(spawnData.pos, nil, minDist) then
spawnData.n1, spawnData.n2 = n1, n2