Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function raymond(a, b, callback, dist, filter)
- if IsEntity(a) then
- a = a:EyePos()
- end
- if IsEntity(b) then
- b = b:EyePos()
- end
- local id = "audiencelaugh" -- tostring(a) .. tostring(b)
- local i = 0
- local mapped = {}
- local last
- local filter = table.Merge({a,b}, filter or {})
- filter = table.Merge(filter, ents.FindByClass("func_door"))
- local function random_dir(dir)
- local len = dir:Length()
- dir = dir:Normalize()
- return LerpVector(((i%100)/100), dir, VectorRand()) * len
- end
- local function line(a, b)
- local dir = random_dir(b-a)
- local data = util.QuickTrace(a, dir, filter)
- debugoverlay.Line(a, data.HitPos, 5, HSVToColor(i%360, 1, 1), true)
- local pos = data.HitPos
- return pos
- end
- local function iterate(a, b, i)
- local pos = line(a, b, i)
- if pos:Distance(b) > (dist or 100) then
- return pos
- else
- return false
- end
- end
- hook.Add("Think", id, function()
- if i%100 == 1 then
- print("searching...")
- end
- for i2 = 0, 200 do
- local pos = iterate(a, b, i)
- if pos then
- if last ~= pos then
- table.insert(mapped, pos)
- end
- a = pos
- last = pos
- else
- hook.Remove("Think", id)
- if callback then
- callback(mapped)
- else
- print(#mapped .. " ray's bounced")
- end
- break
- end
- i = i + 1 + i2
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment