Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

9 comments

0

Nice question

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 :)

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.

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.

0

u could also just google how those desktops do it

0

they have like hunreds of them in lua

0

I think you should mess with Anchor Point or something

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,

0

Great idea

1 answer

✓ Accepted answer

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!

1 comment

0

ik this is a month old but alot of people have this problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.