Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

Help with recreating the Roblox Dragger object.

Asked by 10 years ago

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

1 answer

Log in to vote
0
Answered by 10 years ago

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..

0
1.) to get the offset so the grabbed part doesn't jump to the mouses position 2.) So i could move groups of parts in the future. If I ever get this working I'd like to use it for future projects. MrgamesNwatch 65 — 10y
0
Do a function that checks every ms ("wait()") and then use a ClickDetector, if MousePressed then do another while changing the position to the relative mouse's and the deepness change it on your own (like pressing "e" will deep into the Z, "q" will return back) alessandro112 161 — 10y
0
wait, that's for first person alessandro112 161 — 10y
Ad

Answer this question