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

How To Use Magnitude With UDim2's Scale?

Only need to worry about line 23

local TweenService = game:GetService("TweenService")
script.Prev.Value = "Ref"

script.Parent.Ping.Changed:Connect(function() 
	local CurrentPosition = Vector2.new(0, 1 - (script.Parent.Ping.Value / 500))
	print("CP_: " .. tostring(CurrentPosition))
	local PrevPosition = Vector2.new(script.Parent.Plots[script.Prev.Value].Position.X.Scale, script.Parent.Plots[script.Prev.Value].Position.Y.Scale)
	print("PP_: " .. tostring(Vector2.new(script.Parent.Plots[script.Prev.Value].Position.X.Scale, script.Parent.Plots[script.Prev.Value].Position.Y.Scale)))
	
    local DataPoint = script.LineSegment:Clone()
    DataPoint.Position = UDim2.new(1, 0, 1 - (script.Parent.Ping.Value / 500), 0)
    DataPoint.Parent = script.Parent.Plots
	DataPoint.BackgroundTransparency = 1
	DataPoint.Name = "Plot" .. script.Num.Value
	script.Prev.Value = DataPoint.Name
	
    local LineSegment = script.LineSegment:Clone()
	LineSegment.Position = UDim2.new(1, 0, CurrentPosition.Y * 1, 0)
	print("Pos: " .. tostring(UDim2.new(1, 0, CurrentPosition.Y * 1, 0)))
	local Temp = (CurrentPosition - PrevPosition).Unit * -360
	LineSegment.Rotation = Temp.Y
	print("Rot: " .. tostring(Temp.Y))
	LineSegment.Size = UDim2.new((CurrentPosition - PrevPosition).Magnitude, 0, 0, 2)
	print("Siz: " .. tostring((CurrentPosition - PrevPosition).Magnitude))
    LineSegment.Parent = script.Parent.Plots
	LineSegment.Name = "LineSegment" .. script.Num.Value
	
	script.Num.Value = script.Num.Value + 1

    local goal = {}
    goal.Position = UDim2.new(0, 0, 1 - (script.Parent.Ping.Value / 500), 0)
    local tweenInfo = TweenInfo.new(script.Parent.Speed.Value, 0)
    local tween1 = TweenService:Create(DataPoint, tweenInfo, goal)
    local tween2 = TweenService:Create(LineSegment, tweenInfo, goal)
    tween1:Play()
	tween2:Play()
    wait(script.Parent.Speed.Value)
    DataPoint:Destroy()
    wait(0)
    LineSegment:Destroy()
end)

I have asked this question already and was told to multiply the magnitude by the max magnitude. I have no idea what max magnitude is. Could someone explain it to me like I know nothing about vectors?

In case there is a different answer ill reiterate my original question, I want to get the distance, in scale, between two GUI objects. When I run this though it gives me results nowhere close to what I'm expecting. What am I doing wrong?

Here is the Results

2 comments

0

isnt vector for physical things cuz thats all i know about it

0

@speedyfox66 your thinking of Vector3, which you are correct about, im talking about Vector2

1 answer

.Magnitude of two subtracted values returns the distance from two points. This is no different. Try learning a bit of geometry.

Since these are two points on a 2D plane, you can use Pythagorean theory. Where Leg_1^2 + Leg_2^2 = hypotenuse^2

local function GetDistance(u2val1,u2val2)
	local Leg1 = math.abs(u2val1.X-u2val2.X);
	local Leg2 = math.abs(u2val1.Y-u2val2.Y);
	local hypotenuse = (Leg1^2 + Leg2^2)^.5;
	return hypotenuse;
end;
local a = GetDistance(Vector2.new(0,0),Vector2.new(8,6)) --> should print 10
print(a)-->10

2 comments

0

Yes I understand that. The problem is it’s not working as shown in the results. Pythagorean’s theory would not help here ether because I only have two points and no lengths whatsoever.

0

Just realized I forgot to include the results. Let me do that quick

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