Interesting problem, here’s my solution.
Solution
local UserInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
function angleBetweenSigned(vector1, vector2)
local x1 = vector1.X
local x2 = vector2.X
local y1 = vector1.Y
local y2 = vector2.Y
local angle = math.atan2(x1*y2-y1*x2,x1*x2+y1*y2)
return -angle
end
UserInputService.InputChanged:connect(function(input)
local unitVector2 = Vector2.new(0.482, 0.472) + Vector2.new(input.Delta.X * 0.05, input.Delta.Y * 0.05)
-- Stats
--script.Parent.Parent.Pos.Text = tostring(input.Position)
--script.Parent.Parent.Delta.Text = tostring(unitVector2)
-- Delta Frame
tweenService:Create(script.Parent,
TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
{Position = UDim2.new(unitVector2.X, 0, unitVector2.Y, 0)}):Play()
-- Pointer
local pointer = script.Parent.Parent.Pointer
--Assumes when rotation = 0 degrees, gui arrow is pointing up
local pointerDirection = Vector2.new(math.sin(math.rad(pointer.Rotation)),math.cos(math.rad(pointer.Rotation)))
local deltaDirection = Vector2.new(input.Delta.X, -input.Delta.Y)
local additionalAngle = angleBetweenSigned(pointerDirection, deltaDirection)
additionalAngle = math.deg(additionalAngle)
tweenService:Create(pointer,
TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
{Rotation = pointer.Rotation+additionalAngle}):Play()
end)
How it works is that I converted the GUI.Rotation into a vector2, then found the input delta and converted it into a vector2 then used this angle between vectors formula I found online in the MatLab Forum to find the angular difference between the two vectors whether to rotate clockwise or counterclockwise then I just add this to the current pointer rotation and tell the tweenservice to tween it into that direction.