Created
August 6, 2019 01:50
-
-
Save howmanysmall/7b80eff56687ca058253d8784f1f7a77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--credit to scarious for this god module | |
--t1, origin CFrame | |
--d, distance | |
--s, size (vector3, center based as the middle) | |
--l, ignore list (array) | |
local Workspace = game:GetService("Workspace") | |
local cf =CFrame.new | |
local ray =Ray.new | |
local ipairs = ipairs -- This is SLOW right now but it'll be much faster in the future | |
local function boxcast(t1,d,s,l, rep) | |
--reuse rays if possible in the future | |
if rep then return end | |
local t2=t1*cf(0,0,-((t1.p-(t1*d)).Magnitude)) | |
local x1,y1=s.X/2,s.Y/2 | |
local n0,n1,n2,n3=cf(-x1,-y1,0),cf(-x1,y1,0),cf(x1,y1,0),cf(x1,y1,0) | |
local b0,b1,b2,b3=cf(-x1,0,0),cf(0,y1,0),cf(-x1,0,0),cf(0,-y1,0) | |
local i0,i1,i2,i3,i4,i5,i6,i7=t1*n0,t1*n1,t1*n2,t1*n3,t1*b0,t1*b1,t1*b2,t1*b3 | |
local c0,c1,c2,c3,c4,c5,c6,c7=t2*n0,t2*n1,t2*n2,t2*n3,t2*b0,t2*b1,t2*b2,t2*b3 | |
local ol={t1.p,i0.p,i1.p,i2.p,i3.p,i4.p,i5.p,i6.p,i7.p} | |
local tl={t2.p,c0.p,c1.p,c2.p,c3.p,c4.p,c5.p,c6.p,c7.p} | |
local a=t1.lookVector | |
local ax,ay,az=a.x,a.y,a.z | |
local il=l or {} | |
local h,p,n,c | |
local hs = {} | |
local len = 0 | |
for _, o in ipairs(ol) do | |
for _, t in ipairs(tl) do | |
local to=t-o | |
local h0,p0,n0=Workspace:FindPartOnRayWithIgnoreList(ray(o,to.unit*to.magnitude),il) | |
if h0 and p0 and n0 then | |
local bx,by,bz=p0.x,p0.y,p0.z | |
local ab=ax*bx+ay*by+az*bz | |
local sc=(c and (c>ab and true or false)) or true | |
if sc then | |
local continue = true | |
for _, v in ipairs(hs) do | |
if v == h0 then | |
continue = false | |
break | |
end | |
end | |
if continue then | |
len = len + 1 | |
hs[len] = h0 | |
end | |
end | |
end | |
end | |
end | |
return hs,p,n | |
end | |
return boxcast |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment