Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- function module.Main(a1, a3, tooldebug, m)
- local primaryregionpart = Instance.new("Part", game.Lighting) -- make the box that will determine the region3
- primaryregionpart.Transparency = 1
- if tooldebug then primaryregionpart.Transparency = 0.5 end
- primaryregionpart.CanCollide = false
- primaryregionpart.Anchored = true
- primaryregionpart.CastShadow = false
- primaryregionpart.Parent = game.Workspace -- prepare this
- local cam = workspace.CurrentCamera -- make sure our camera is up to date
- local camcf = cam.CFrame -- save this before calculations to prevent bad stuff
- -- documentation for the questionable mental state code below if you want to understand it:
- --[[
- a1, a2, a3, a4 are the corners of the selection gui when the player started and ended holding left mouse button
- r means that it is the ray casted from the camera for that location
- s means that it is the on screen position, aka the vector3 of the vector2 of the camera
- d = distance
- m = midpoint
- p = prime (this means it was farther away)
- tmp = temp, as in it's only going to be used once and i couldn't be asked to make another letter for it
- a letter added on means its one of those things above
- for example
- a123ms would be the midpoint of a1, a2, and a3 at the player's coordinates (the corners of the gui they dragged)
- ]]
- local a2 = Vector2.new(a1.X, a3.Y) -- make a vector2 for a2
- local a4 = Vector2.new(a3.X, a1.Y)
- if tooldebug then print("All points:", a1, a2, a3) end
- local a1r = cam:ScreenPointToRay(a1.X, a1.Y) -- get the thing from lego game
- local a2r = cam:ScreenPointToRay(a2.X, a2.Y)
- local a3r = cam:ScreenPointToRay(a3.X, a3.Y)
- local a4r = cam:ScreenPointToRay(a4.X, a4.Y)
- local a1r = Ray.new(a1r.Origin, a1r.Direction * 0) -- make the rays
- local a2r = Ray.new(a2r.Origin, a2r.Direction * 0)
- local a3r = Ray.new(a3r.Origin, a3r.Direction * 0)
- local a4r = Ray.new(a4r.Origin, a4r.Direction * 0)
- local _, a1s = workspace:FindPartOnRay(a1r, cam) -- get the position, we don't actually care about the part xd
- local _, a2s = workspace:FindPartOnRay(a2r, cam)
- local _, a3s = workspace:FindPartOnRay(a3r, cam)
- local _, a4s = workspace:FindPartOnRay(a4r, cam)
- local a1p = (CFrame.new(a1s, camcf.p) * CFrame.new(0, 0, 300)).p -- get our prime values
- local a2p = (CFrame.new(a2s, camcf.p) * CFrame.new(0, 0, 300)).p
- local a3p = (CFrame.new(a3s, camcf.p) * CFrame.new(0, 0, 300)).p
- local a4p = (CFrame.new(a4s, camcf.p) * CFrame.new(0, 0, 300)).p
- local function makepointparts(x) -- debug function
- print("Creating debug parts.")
- for i, v in pairs(x) do
- local p = Instance.new("Part", game.Workspace)
- p.Anchored = true
- p.CanCollide = false
- p.CastShadow = false
- p.BrickColor = BrickColor.new("Storm blue")
- p.Material = Enum.Material.Neon
- p.Size = Vector3.new(0.05, 0.05, 0.05)
- p.Position = v
- p.Name = "dbgpart"
- if i > 4 then p.Size = Vector3.new(10, 10, 10) end
- end
- end
- local a1234pm = (a1p + a2p + a3p + a4p) / 4
- local a1234sm = (a1s + a2s + a3s + a4s) / 4
- local a1234spm = (a1234pm + a1234sm) / 2
- local a1234dspm = (a1234pm - a1234sm).magnitude
- local a12pd = (a1p - a2p).magnitude -- used to be height
- local a14pd = (a1p - a4p).magnitude -- used to be thick
- local function calcpoints(a1s, a2s, a1p, a2p, mod1, mod2) -- function works in terms of a1 and a2 but really takes any two points
- -- still requries thick and height though
- local removebox = Instance.new("Part") -- make the removebox, and set basic properties
- removebox.Anchored = true
- removebox.CanCollide = false
- removebox.CastShadow = false
- removebox.Transparency = 1
- removebox.BrickColor = BrickColor.new("Really red")
- removebox.Size = Vector3.new(1, 1, 1)
- removebox.Locked = true
- if tooldebug then removebox.Transparency = 0.5 end -- debugging
- removebox.Parent = game.Workspace
- local a12sm = (a1s + a2s) / 2
- local a12pm = (a1p + a2p) / 2 -- get the mid between the two points given
- local a12dpsm = (a12sm - a12pm).magnitude -- get the magnitude between those
- removebox.Size = Vector3.new(a14pd, a12pd, a12dpsm) -- set the size
- local a14pdtmp
- local a12pdtmp
- if mod2 then -- determines what changes to the operation need to be made based off of orientation
- a14pdtmp = a14pd / mod1
- a12pdtmp = 1
- else
- a14pdtmp = 1
- a12pdtmp = a12pd / mod1
- end
- removebox.CFrame = (CFrame.new(a12sm, a12pm) * CFrame.new(a14pdtmp, a12pdtmp, a1234dspm / -2)) -- set the cframe
- return removebox
- end
- local bp1 = calcpoints(a1s, a2s, a1p, a2p, 2, true)
- local bp2 = calcpoints(a2s, a3s, a2p, a3p, -2, false) -- inv
- local bp3 = calcpoints(a3s, a4s, a3p, a4p, -2, true)
- local bp4 = calcpoints(a4s, a1s, a4p, a1p, 2, false) -- inv
- primaryregionpart.Position = a1234spm
- primaryregionpart.Size = Vector3.new(a12pd, a14pd, a1234dspm)
- primaryregionpart.CFrame = CFrame.new(primaryregionpart.Position, a1234pm)
- if tooldebug then makepointparts({a1s, a2s, a3s, a4s, a1p, a2p, a3p, a4p}) end
- return primaryregionpart, bp1, bp2, bp3, bp4
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement