Hi, I’m currently using the UserInputService.TouchMoved event to check if a player is trying to pan their camera in my custom camera script. The only issue is that I don’t want it to pan if the player touched within a frame. Is there a way I can detect if they tapped within a specific frame?
I’ve thought about using AbsoluteSize/AbsolutePosition, but I don’t know the crazy maths I need to do to achieve my goal.
Here is what I got so far:
userInputService.TouchMoved:Connect(function(input)
xAngle = xAngle-input.Delta.x*0.3
--Clamp the vertical axis so it doesn't go upside down or glitch.
yAngle = math.clamp(yAngle-input.Delta.y*0.3, -35, 30)
end)
There might be a better option and I’m not the guy to ask for it, but this is actually not crazy math at all.
local pos = input.Position
local onGui = false
for _, someGui in pairs(tableOfGuis) do
local guiSize = someGui.AbsoluteSize
local guiPos = someGui.AbsolutePosition
if (pos.X > guiPos.X) and (pos.X < guiPos.X + guiSize.X) and (pos.Y > guiPos.Y) and (pos.Y < guiPos.Y + guiSize.Y) then
onGui = true
break
end
end
if onGui then
print("Tapped a GUI!")
end
If you wanted to check if the player’s input was focused onto a specific frame for example you could simply use the MouseEnter event that most roblox gui objects have built into them and than check if there mouse is currently within the frame, or you could go for a more mathematical approach like @JarodOfOrbiter is suggesting
Correct me if I’m wrong, but I’ve never found that to be reliable. Is it reliable?
Also, Wizzred, you should definitely make sure that they aren’t initially touching within a frame, but that they are allowed to afterwards. Otherwise, it could be annoying trying to pan the camera but hitting a GUI during the swipe. Try flow like this.
UIS.TouchBeganIThink:Connect(function(yeh)
-- check if it was touched on a GUI
-- if not then
moving = true
end)
UIS.TouchEndedIThink:Connect(function(oYeh)
moving = false
end)
UIS.TouchMoved:Connect(ohHEKyeh)
if moving then
--- do the camerr move
end
end)
where does the break come in bruh
and also, this is the final working code right?
game:GetService("UserInputService").TouchMoved:Connect(function(input)
local pos = input.Position
onGui = false
local guiSize = script.Parent.AbsoluteSize
local guiPos = script.Parent.AbsolutePosition
if (pos.X > guiPos.X) and (pos.X < guiPos.X + guiSize.X) and (pos.Y > guiPos.Y) and (pos.Y < guiPos.Y + guiSize.Y) then
onGui = true
end
end)
if onGui then
print("Tapped a GUI!")
end
end
You need to reorder some of those lines so that it all fits in the function. If you’re not using a for loop, then you don’t need a break or even onGui.
game:GetService("UserInputService").TouchMoved:Connect(function(input)
local pos = input.Position
local guiSize = script.Parent.AbsoluteSize
local guiPos = script.Parent.AbsolutePosition
if (pos.X > guiPos.X) and (pos.X < guiPos.X + guiSize.X) and (pos.Y > guiPos.Y) and (pos.Y < guiPos.Y + guiSize.Y) then
print("Tapped a GUI!")
end
end)