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

Attempting to scale a part from a specific corner? [UPDATE]

Asked by 5 years ago
Edited 5 years ago

I am trying to make a selection box when you drag your mouse. Like you do on your desktop to select multiple icons.

I have the basics of the code down but my problem is when I drag in any other quadrant than the 4th I the part doesnt position correctly. By quadrant I mean, think of a graph and the bottom right square is quadrant 4.

Heres my code so far.

local SelectionStartPosition
local SelectionEndPosition

function SelectionBegan()
    SelectionStartPosition = Mouse.Hit.Position
end

function SelectionEnded()
    SelectionEndPosition = Mouse.Hit.Position

    local SelectionPart = Instance.new("Part")
    SelectionPart.Size = Vector3.new(math.abs(SelectionStartPosition.X - SelectionEndPosition.X), math.abs(SelectionStartPosition.Y - SelectionEndPosition.Y), math.abs(SelectionStartPosition.Z - SelectionEndPosition.Z))
    SelectionPart.Position = SelectionStartPosition - Vector3.new(SelectionPart.Size.X/2, 0, SelectionPart.Size.Z/2)
    SelectionPart.Anchored = true
    SelectionPart.Parent = workspace
end

Mouse.Button1Down:Connect(SelectionBegan)
Mouse.Button1Up:Connect(SelectionEnded)

Thank you for your time :)

Heres an image of a chart just in case your curious. http://aventalearning.com/content168staging/2006AlgebraIA/images/u4_s1_3.gif

Also heres a gif of the top bottom thing I was talking about. https://gyazo.com/2289dd3041144fd777db401f6939d944

[UPDATE] I have managed to solve the scaling problem, by converting the scale numbers into positive numbers that seems to work :) Now I am trying to solve the positioning problem.

0
Nice question greatneil80 2647 — 5y
0
I updated it, I have been messing around with it for a little while but now ive come across a different problem. Also thank you for the up vote :) GottaHaveAFunTime 218 — 5y
0
I had this same question, and a satisfactory solution for me was to just change the size of a cylinder mesh through a for I loop. I wanted the cylinder to go from being flat to rising in height from bottom to top, not increasing in size from the center. ScrubSadmir 200 — 5y
0
I almost have it solved on my own, Ill paste the solved code here when im done just incase anyone ever wants to see the math for it. GottaHaveAFunTime 218 — 5y
View all comments (5 more)
0
u could also just google how those desktops do it TheluaBanana 946 — 5y
0
they have like hunreds of them in lua TheluaBanana 946 — 5y
0
I think you should mess with Anchor Point or something NorteX_tv 101 — 5y
0
Have you tried to make a replica of what the part would look like at first? It be better to help analyze your problem in my opinion, TheePBHST 154 — 5y
0
Great idea Void_Frost 571 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

A simple way to do this is by using the Anchor Point property. So, for instance,

local guiObj = script.Parent
guiObj.AnchorPoint = Vector3.new(0.5,0.5)
while wait() do
    guiObj .Size = guiObj .Size + UDim2.new(0,1,0,1)
end

The code above with make the gui object expand from the center

So, if you wanted to expand the gui object from the top right you would do this:

local guiObj = script.Parent
guiObj.AnchorPoint = Vector3.new(1,0)
while wait() do
    guiObj .Size = guiObj .Size + UDim2.new(0,1,0,1)
end

Hope this helped!

0
ik this is a month old but alot of people have this problem. Le_JuiceBOX 54 — 5y
Ad

Answer this question