I'm recreating the dragger object to seamlessly work with code that uses it already, all is well except I can't quite figure out that actual part dragging.
Basically I need to come up with a function that can take a table of parts, an offset point (the point grabbed at), and a new CFrame (that being mouse.hit). How might I do that? Also how would i get parts to stick to the side of other parts instead of popping on top?
My code so far (in a module script):
local Dragger = { MainPart = nil, GrabPoint = Vector3.new(), Parts = {}, IsDown = false, MoveParts = (function(self, Parts, Offset, New) -- Here's where i'm stuck end), MouseDown = (function(self, MousePart, PointOnMousePart, Parts) print("Down") if self.IsDown == false then --set MainPart, GrabPoint, and Parts, Set IsDown to true. self.MainPart = MousePart self.GrabPoint = PointOnMousePart self.Parts = Parts self.IsDown = true else pcall(error("MouseDown is in use, call MouseUp before using again")) end end), MouseMove = (function(self,MouseRay) print("Move") if self.IsDown == true then --Move GrabPoint and Parts relative to GrabPoint local NewRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 999) local RayPart, RayHit = Workspace:FindPartOnRayWithIgnoreList(NewRay, self.Parts) if RayPart then print(self.GrabPoint) self:MoveParts(self.Parts, CFrame.new(self.GrabPoint), CFrame.new(RayHit)) end else error("MouseMoved called without MouseDown") end end), MouseUp = (function(self) print("Up") --stop the dragging action, clear mainpart, grabpoint, parts, Set IsDown to false. if self.IsDown == true then self.MainPart = nil self.GrabPoint = Vector3.new() self.Parts = {} self.IsDown = false else error("MouseUp called before MouseDown") end end), AxisRotate = (function(self, Axis) --Rotate on the given axis if Axis == 0 or Axis == Enum.Axis.X or (type(Axis) == "string" and Axis:lower() == "x")then Axis = CFrame.Angles(90,0,0) elseif Axis == 1 or Axis == Enum.Axis.Y or (type(Axis) == "string" and Axis:lower() == "y") then Axis = CFrame.Angles(0,90,0) elseif Axis == 2 or Axis == Enum.Axis.Z or (type(Axis) == "string" and Axis:lower() == "z") then Axis = CFrame.Angles(0,0,90) --[[else Axis = CFrame.Angles(0,0,0)--]] end print(Axis) self:MoveParts(self.Parts, CFrame.new(self.GrabPoint), CFrame.new(self.GrabPoint) * Axis) end) } return Dragger
Two things:
1)Why did you do a script that check the position of the GrabPoint instead of getting the mouse position?
2)Parts = {},
why? You need to move only 1 part..