laneChange
Definition
-- @/lua/vehicle/ai.lua:1169
local function laneChange(plan, dist, signedDisp)
if not plan and currentRoute then plan = currentRoute.plan end
if not plan then return end
-- Apply node displacement
local invDist = 1 / (dist + 1e-30)
local curDist, normalDispVec = 0, vec3()
for i = 2, plan.planCount do
openLaneToLaneRange(plan[i])
curDist = curDist + plan[i-1].length
plan[i].lateralXnorm = clamp(plan[i].lateralXnorm + signedDisp * min(curDist * invDist, 1), plan[i].laneLimLeft, plan[i].laneLimRight)
normalDispVec:setScaled2(plan[i].normal, plan[i].lateralXnorm)
plan[i].pos:setAdd2(plan[i].posOrig, normalDispVec)
-- Recalculate vec and dirVec
plan[i].vec:setSub2(plan[i-1].pos, plan[i].pos); plan[i].vec.z = 0
plan[i].dirVec:set(plan[i].vec)
plan[i].dirVec:normalize()
end
updatePlanLen(plan)
--[[ For debugging
table.clear(newPositionsDebug)
for i = 1, #newPositions do
newPositionsDebug[i] = vec3(newPositions[i])
end
--]]
end
Callers
@/lua/ge/extensions/gameplay/traffic/baseRole.lua
-- this should really be done in ai.lua instead
self.veh.queuedFuncs.laneChange = {timer = 0.25, vLua = 'ai.laneChange(nil, '..changeLaneDist..', '..sideDist..')'}
self.veh.queuedFuncs.setStopPoint = {timer = 0.25, vLua = 'ai.setStopPoint(nil, '..(changeLaneDist + 20)..')'}
@/lua/vehicle/ai.lua
laneChange(plan, max(10, dist - 20), disp * side)
setStopPoint(plan, dist, {avoidJunction = true})
if not pullOver and trafficStates.action.forcedStop then
--laneChange(plan, 40, -trafficStates.side.displacement) -- this is no longer needed?
setStopPoint()