Moving a UI object at an angle

I’ve looked it up before, and tried the solution but it didn’t work for me, and I’m not sure why.
Rather than provide their solution and ask for help, I’ll put my original code, explain it, and ask why it didn’t work. Also, as far as a solution goes, please don’t just post a fix, I want it to be explained such that I can understand it and manipulate it for myself in the future.

--For the record, script.Parent is the gui object (a textbutton)
--Its angle is 10 degrees, its size is the default textbutton size, and the anchor point is .5, .5

--Get slope using trig
local slope = math.tan(math.rad(script.Parent.Rotation))

script.Parent.MouseButton1Down:Connect(function()
	
	local pos = script.Parent.Position
	
	local endX = pos.X.Scale - .25 --get our end x
	local endY = pos.Y.Scale + (slope * (endX - pos.X.Scale)) --get end y by multiplying our delta x 
                                              --by the slope and adding it to the original y
	
	script.Parent:TweenPosition(UDim2.new(endX, 0, endY, 0))
	
	
end)

NOTE: I am in fact working with scale, not offset.


This is how the object starts; I have a green line with the same rotation to visualize the path it SHOULD take as it moves left across the screen…

versus where it ends up…

So yeah, can anyone explain why this isn’t working and how to fix it?

EDIT: Changed the code to multiply by delta x rather than our end x, because that seems to make more mathematical sense after I reviewed it. Code still does not work properly.
EDIT 2: Reverted inversion of slope because I don’t think it’s necessary. Regardless, code still does not work properly.

5 Likes

is the anchorPoint set to 0,0 instead of 0.5,0.5? that seems like what’s happening

2 Likes

No, it’s 0.5, 0.5
Also, I’m not sure how anchor point would affect anything

1 Like

I was thinking about it, and I think the reason this isn’t working is because scale is a ratio of the size of the screen, meaning that where in a normal coordinate plane the scales of the X and Y axis are equal (like offset) whereas scale provides different ones which kind of squishes it, providing an apparent distortion in the slope