Most input events in UserInputService also exist in GuiObject , except for UserInputService.PointerAction
Does anyone here know how to implement the UserInputService’s PointerAction event on a GuiObject?
The PointerAction event is essential for camera rotation using a mouse and touchpad.
You might say to retrieve PointerAction’s wheel, pan, and pinch from the InputObject’s Position, but they aren’t the same
UserInputService.PointerAction:Connect(function(wheel, pan, pinch, gpe)
print(
`wheel: {wheel}\n`
)
end)
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseWheel then
return
end
print(`wheel position: {input.Position.Z}`)
end)
local UserInputService = game:GetService("UserInputService")
local GuiObject = script.Parent:WaitForChild("YourGuiObject") -- Replace with your actual GuiObject
-- Function to check if a point is within the GuiObject bounds
local function isPointInGuiObject(guiObject, point)
local absPos = guiObject.AbsolutePosition
local absSize = guiObject.AbsoluteSize
return point.X >= absPos.X and point.X <= absPos.X + absSize.X and point.Y >= absPos.Y and point.Y <= absPos.Y + absSize.Y
end
-- Capture PointerAction events
UserInputService.PointerAction:Connect(function(wheel, pan, pinch, gpe)
-- Check if the pointer is over the GuiObject
local mousePosition = UserInputService:GetMouseLocation()
if isPointInGuiObject(GuiObject, mousePosition) then
-- Fire a custom event or handle the action in the context of the GuiObject
print(`PointerAction on GuiObject - wheel: {wheel}, pan: {pan}, pinch: {pinch}, gpe: {gpe}`)
-- Your custom handling logic here
end
end)
-- Capture MouseWheel events as a fallback or additional functionality
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseWheel then
local mousePosition = UserInputService:GetMouseLocation()
if isPointInGuiObject(GuiObject, mousePosition) then
print(`MouseWheel on GuiObject - wheel position: {input.Position.Z}`)
-- Your custom handling logic here
end
end
end)