Inaccurate input on Handles and ArcHandles

Hi, i got told from a moderator to report this minor bug i experienced today in Studito you via Dms since im currently not able to make a post under the bugs category.

Description:
I just found out that by moving the camera to the side of the player using the module in this post: Non-central offset for the Camera's Focus or Field of View the inputs of Handles and ArcHandles are moved away from the displayied handle.

Heres a post i previously made about it, got hidden.
https://devforum.roblox.com/t/buggy-input-on-handlers-and-archandlers/3114865


As you can see the hover input (and any other) is fired when the mouse pointer its not supposed to be. I know this is probably related to the rendering but would be nice to improve it.

Reproduce:
Create a new ArcHandles or Handles in PlayerGui and set the Adornee property to any object.
Require the module and start it with the following script:

How i setupped the module:

local viewHandler = require(module)
viewHandler.Position = UDim2.fromScale(0.35, 0)
viewHandler.Size = UDim2.fromScale(0.75, 0.75)
viewHandler.StartStatic()

My edited version of the module:

local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera

local module = {}
module.Position = UDim2.new(0, 0, 0, 0)
module.Size = UDim2.new(1, 0, 1, 0)

local function UDim2Absolute(udim2)
	local viewSize = Camera.ViewportSize

	return Vector2.new(
		(udim2.X.Scale * viewSize.X) + udim2.X.Offset,
		(udim2.Y.Scale * viewSize.Y) + udim2.Y.Offset
	)
end

--- Compute offset

function module._computePosition()
	local viewSize = Camera.ViewportSize
	local aspectRatio = viewSize.X / viewSize.Y

	local offset = UDim2Absolute(module.Position)
	local position = offset / viewSize

	-- Taken from ScreenSpace
	local hFactor = math.tan(math.rad(Camera.FieldOfView) / 2)
	local wFactor = hFactor * aspectRatio

	return -position.X * wFactor * 2, position.Y * hFactor * 2
end

function module._computeSize()
	local size = UDim2Absolute(module.Size) / Camera.ViewportSize
	return size.X, size.Y
end

function module._getOffset()
	local x, y = module._computePosition()
	local w, h = module._computeSize()

	return CFrame.new(
		0, 0, 0,

		w, 0, 0,
		0, h, 0,
		x, y, 1
	)
end

--- Handler

function module.Start()
	module.Stop()
	RunService:BindToRenderStep("ViewportResizer", Enum.RenderPriority.Camera.Value + 1, function()
		Camera.CFrame = Camera.CFrame * module._getOffset()
	end)
end

function module.StartStatic() -- A lot more efficient when there are no dynamic changes to the properties
	local offset = module._getOffset()
	module.Stop()
	
	RunService:BindToRenderStep("ViewportResizer", Enum.RenderPriority.Camera.Value + 1, function()
		Camera.CFrame = Camera.CFrame * offset
	end)
end

function module.Stop()
	RunService:UnbindFromRenderStep("ViewportResizer")
end

return module

Ty for your time :wink:

Thanks for the report! Just sent this over to the team. We’ll update you as soon as we can :slight_smile:

1 Like