I made a script which locks a model to the users mouse using “mouse.TargetFilter” and on a mouse enabled device you click to confirm it’s placement.
To make it compatible on touch screen devices, I made a GUI appear for the user to tap themselves but the problem is that upon tapping the GUI, the item moves directly underneath it and is subsequently placed there and I believe the problem to be “mouse.TargetFilter”.
If you’re using InputService try using the GameProcessed parameter, it will tell you if the player is interacting with a UI element. Modify the placing function so if the parameter returns true you don’t do anything.
mouse.TargetFilter is a property of the mouse that prevents an object and it’s descendants from being registered for mouse.Hit. Not only should you not be using mouse properties for mobile, but this
is bad UX. Users don’t get to see where they’re placing things; they only get to move an item to a location and place it there as well. You should instead look to double tapping or confirmation panels.
That aside, mouse.TargetFilter and an input position are independent of each other. So the answer: no.
Is this possible to do with ContextActionService
since I’m under the impression that you can assign multiple inputs to the same task?
It is, indeed. The process you’ll want to follow is that every tap results in the movement of an object and a subsequent tap within a certain timeframe (such as 0.3 seconds) places the object.
Something like this.
local ContextActionService = game:GetService("ContextActionService")
local lastTap = 0
ContextActionService:BindActionAtPriority("TapFunction", function(inputObject)
if inputObject.UserInputState == Enum.UserInputState.Begin then
if lastTap + 0.3 > tick() then
-- Place
else
lastTap = tick()
-- Move to tap location
end
end
end, false, Enum.ContextActionPriority.Default.Value + 25, Enum.UserInputType.TouchTap)
Obviously not this exact code, have no clue if this even works or if it’s proper, but this is about what you’ll want to look for. If you want an alternative to mouse.Hit, extend a unit ray from ViewportPointToRay with the position supplied in the InputObject.
Thank you, I’ll try to implement this now and will provide an update.
EDIT: Supplying a unit ray into inputObject worked perfectly