Files
tokyo-wangan-racing/tools/diag_raycast.luau
T
jesse 7d368d5444 Render C1 structural variety: girder bridges, Ginza overpasses, JCT speeds, 3+3 widening
Four fidelity fixes, all verified in a live Studio datamodel (not just built):

1. Wire up the dead `bridge` flag. Circuit.luau marks 474 samples as bridge
   spans but nothing ever read the field, so every elevated metre rendered as
   the same slab on square columns. Flagged spans now get a steel box girder
   (鋼箱桁橋) with stiffener ribs under the deck, carried on a transverse pier
   cap and round columns at a wider pitch than the viaduct pillars.

2. Ginza 跨道橋. The Ginza section sits below street level in the filled-in
   楓川・築地川 river beds and the surviving city bridges cross over it, their
   piers landing in the median. Adds the crossing decks, parapets and centre
   piers -- which is the physical reason lane changes are banned there, not
   just a paint choice.

3. Junction speed plates. 江戸橋JCT内 / 浜崎橋JCT内 / 京橋JCT-旧白魚橋乗継所 are
   posted 40 km/h, not the 50 km/h mainline limit; plates repeat more often
   through the short restricted stretches.

4. Shiodome JCT -> Hamazakibashi JCT widened to 3+3 lanes via widthAt(), with
   a taper (max ~1.7 studs/sample) instead of a step. Every fixed-width
   consumer -- deck, median, parapets, lane marks, signage offsets, skyline
   setback, finish line -- now reads widthAt() so nothing floats or clips.

Verified headlessly (tools/verify_c1_fixes*.luau):
  girders 488 / 474 flagged samples, pier caps 85, columns 80
  Ginza overpasses 7, piers 7, lateral offset from centreline 0.000 studs
  speed plates 40km/h x7, 50km/h x8
  deck width Shiodome 81.5 vs Kasumigaseki 60.0
  seam lip max 0.0006, road-surface raycast step max 0.260, 0 deck holes

Two earlier "failures" were bad tests, not bad geometry, and the fixed
harnesses document the traps: deck parts are pitched by CFrame.lookAt so
Position.Y+Size.Y/2 is not the surface height (and LookVector is -Z, so the
end faces are easy to swap), and a seam raycast must filter to the Expressway
folder or it hits TunnelCeiling/MedianFence and reports a phantom 19-stud step.
2026-08-01 18:10:00 -04:00

70 lines
2.4 KiB
Luau

-- Diagnose the raycast outlier: report WHICH parts the rays hit.
-- The v3 raycast filtered on the whole map, so overhead geometry (overpass
-- decks, girders, gantries, tunnel ceilings) can be hit before the road.
local sss = game:GetService("ServerScriptService")
local orig = sss:FindFirstChild("MapBuilder", true)
local clone = orig:Clone()
clone.Name = "MapBuilder_Diag"
clone.Parent = orig.Parent
local MB = require(clone)
local map = MB.build()
local Circuit = require(game:GetService("ReplicatedStorage"):FindFirstChild("Circuit", true))
local samples = Circuit.samples
local n = #samples
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Include
rp.FilterDescendantsInstances = { map }
local out = {}
-- Road-only params: what the driver actually touches.
local roadOnly = RaycastParams.new()
roadOnly.FilterType = Enum.RaycastFilterType.Include
roadOnly.FilterDescendantsInstances = { map:FindFirstChild("Expressway") }
local worstAll, worstRoad, atAll, atRoad = 0, 0, -1, -1
local hits = {}
for i = 1, n do
local j = (i % n) + 1
local p = samples[j].pos
local fwd = (samples[(j % n) + 1].pos - samples[i].pos)
fwd = Vector3.new(fwd.X, 0, fwd.Z)
if fwd.Magnitude > 0.01 then
fwd = fwd.Unit
local o1 = p - fwd * 3 + Vector3.new(0, 40, 0)
local o2 = p + fwd * 3 + Vector3.new(0, 40, 0)
local a1 = workspace:Raycast(o1, Vector3.new(0, -120, 0), rp)
local a2 = workspace:Raycast(o2, Vector3.new(0, -120, 0), rp)
if a1 and a2 then
local d = math.abs(a1.Position.Y - a2.Position.Y)
if d > worstAll then
worstAll, atAll = d, i
end
if d > 1 then
hits[#hits + 1] = ("i=%d(%s) d=%.2f hitA=%s hitB=%s"):format(
i, samples[i].piece, d, a1.Instance.Name, a2.Instance.Name)
end
end
local b1 = workspace:Raycast(o1, Vector3.new(0, -120, 0), roadOnly)
local b2 = workspace:Raycast(o2, Vector3.new(0, -120, 0), roadOnly)
if b1 and b2 then
local d = math.abs(b1.Position.Y - b2.Position.Y)
if d > worstRoad then
worstRoad, atRoad = d, i
end
end
end
end
out[#out + 1] = ("ALL-GEOMETRY worst=%.3f at i=%d"):format(worstAll, atAll)
out[#out + 1] = ("ROAD-ONLY worst=%.3f at i=%d -> %s"):format(
worstRoad, atRoad, worstRoad <= 0.60 and "PASS" or "FAIL")
out[#out + 1] = ("outlier samples (d>1), first 12 of %d:"):format(#hits)
for k = 1, math.min(12, #hits) do
out[#out + 1] = " " .. hits[k]
end
map:Destroy()
clone:Destroy()
return table.concat(out, "\n")