Skip to content

Instantly share code, notes, and snippets.

@Elmuti
Created April 29, 2015 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elmuti/faeacfc1cdb45d1514f9 to your computer and use it in GitHub Desktop.
Save Elmuti/faeacfc1cdb45d1514f9 to your computer and use it in GitHub Desktop.
function getRayEntranceAndExit(pos, dir, distance)
local ignore = deepcopy(_G.ignorelist)
local Ray1 = Ray.new(pos, dir.unit*distance)
local obj, enter, enterface = workspace:FindPartOnRayWithIgnoreList(Ray1, _G.ignorelist)
if obj ~= nil then
table.insert(ignore, obj)
end
local Ray2 = Ray.new(enter, dir.unit*distance)
local _, hpos2 = workspace:FindPartOnRayWithIgnoreList(Ray2, ignore)
local Ray3 = Ray.new(hpos2, CFrame.new(hpos2, enter).lookVector.unit*distance)
local _, exit, exitface = workspace:FindPartOnRayWithIgnoreList(Ray3, _G.ignorelist)
return obj, enter, exit, vectorToFace(obj, enterface), vectorToFace(obj, exitface)
end
@Elmuti
Copy link
Author

Elmuti commented Apr 29, 2015

function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
setmetatable(copy, deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment